JNA API 3.0.9

com.sun.jna
Class Function

java.lang.Object
  extended by com.sun.jna.Pointer
      extended by com.sun.jna.Function

public class Function
extends Pointer

An abstraction for a native function pointer. An instance of Function represents a pointer to some native function. invoke(Class,Object[],Map) is the primary means to call the function.

Author:
Sheng Liang, originator, Todd Fast, suitability modifications
See Also:
Pointer

Nested Class Summary
static interface Function.PostCallRead
          Any argument which implements this interface will have the Function.PostCallRead.read() method called immediately after function invocation.
 
Field Summary
static int ALT_CONVENTION
          First alternate convention (currently used only for w32 stdcall).
static int C_CONVENTION
          Standard C calling convention.
(package private) static Integer INTEGER_FALSE
           
(package private) static Integer INTEGER_TRUE
           
static int MAX_NARGS
          Maximum number of arguments supported by a JNA function call.
(package private) static String OPTION_INVOKING_METHOD
          For internal JNA use.
 
Fields inherited from class com.sun.jna.Pointer
NULL, peer, SIZE
 
Constructor Summary
Function(NativeLibrary library, String functionName, int callingConvention)
          Create a new Function that is linked with a native function that follows the given calling convention.
Function(Pointer functionAddress, int callingConvention)
          Create a new Function that is linked with a native function that follows the given calling convention.
 
Method Summary
(package private) static Object[] concatenateVarArgs(Object[] inArgs)
          Concatenate varargs with normal args to obtain a simple argument array.
 boolean equals(Object o)
          Two function pointers are equal if they share the same peer address and calling convention.
 int getCallingConvention()
           
static Function getFunction(String libraryName, String functionName)
          Obtain a Function representing a native function that follows the standard "C" calling convention.
static Function getFunction(String libraryName, String functionName, int callConvention)
          Obtain a Function representing a native function that follows a given calling convention.
 String getName()
           
 Object invoke(Class returnType, Object[] inArgs)
          Invoke the native function with the given arguments, returning the native result as an Object.
 Object invoke(Class returnType, Object[] inArgs, Map options)
          Invoke the native function with the given arguments, returning the native result as an Object.
 void invoke(Object[] args)
          Call the native function being represented by this object
(package private)  Object invoke(Object[] args, Class returnType)
           
 double invokeDouble(Object[] args)
          Convenience method for invoke(Double.class, args).
 float invokeFloat(Object[] args)
          Convenience method for invoke(Float.class, args).
 int invokeInt(Object[] args)
          Convenience method for invoke(Integer.class, args).
 long invokeLong(Object[] args)
          Convenience method for invoke(Long.class, args).
 Pointer invokePointer(Object[] args)
          Convenience method for invoke(Pointer.class, args).
 String invokeString(Object[] args, boolean wide)
          Convenience method for invoke(String.class, args) or invoke(WString.class, args)
 void invokeVoid(Object[] args)
          Convenience method for invoke(Void.class, args).
(package private) static boolean isVarArgs(Method m)
          Varargs are only supported on 1.5+.
 String toString()
          Provide a human-readable representation of this object.
(package private) static Boolean valueOf(boolean b)
          Implementation of Boolean.valueOf for older VMs.
 
Methods inherited from class com.sun.jna.Pointer
clear, createConstant, getByte, getByteArray, getByteBuffer, getChar, getCharArray, getDouble, getDoubleArray, getFloat, getFloatArray, getInt, getIntArray, getLong, getLongArray, getNativeLong, getPointer, getPointerArray, getPointerArray, getShort, getShortArray, getString, getString, getStringArray, getStringArray, hashCode, indexOf, read, read, read, read, read, read, read, read, setByte, setChar, setDouble, setFloat, setInt, setLong, setMemory, setNativeLong, setPointer, setShort, setString, setString, share, share, write, write, write, write, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_NARGS

public static final int MAX_NARGS
Maximum number of arguments supported by a JNA function call.

See Also:
Constant Field Values

C_CONVENTION

public static final int C_CONVENTION
Standard C calling convention.

See Also:
Constant Field Values

ALT_CONVENTION

public static final int ALT_CONVENTION
First alternate convention (currently used only for w32 stdcall).

See Also:
Constant Field Values

INTEGER_TRUE

static final Integer INTEGER_TRUE

INTEGER_FALSE

static final Integer INTEGER_FALSE

OPTION_INVOKING_METHOD

static final String OPTION_INVOKING_METHOD
For internal JNA use.

See Also:
Constant Field Values
Constructor Detail

Function

Function(NativeLibrary library,
         String functionName,
         int callingConvention)
Create a new Function that is linked with a native function that follows the given calling convention.

The allocated instance represents a pointer to the named native function from the supplied library, called with the given calling convention.

Parameters:
library - NativeLibrary in which to find the function
functionName - Name of the native function to be linked with
callingConvention - Calling convention used by the native function
Throws:
{@link - UnsatisfiedLinkError} if the given function name is not found within the library.

Function

Function(Pointer functionAddress,
         int callingConvention)
Create a new Function that is linked with a native function that follows the given calling convention.

The allocated instance represents a pointer to the given function address, called with the given calling convention.

Parameters:
functionAddress - Address of the native function
callingConvention - Calling convention used by the native function
Method Detail

getFunction

public static Function getFunction(String libraryName,
                                   String functionName)
Obtain a Function representing a native function that follows the standard "C" calling convention.

The allocated instance represents a pointer to the named native function from the named library, called with the standard "C" calling convention.

Parameters:
libraryName - Library in which to find the native function
functionName - Name of the native function to be linked with
Throws:
{@link - UnsatisfiedLinkError} if the library is not found or the given function name is not found within the library.

getFunction

public static Function getFunction(String libraryName,
                                   String functionName,
                                   int callConvention)
Obtain a Function representing a native function that follows a given calling convention.

The allocated instance represents a pointer to the named native function from the named library, called with the named calling convention.

Parameters:
libraryName - Library in which to find the function
functionName - Name of the native function to be linked with
callConvention - Call convention used by the native function
Throws:
{@link - UnsatisfiedLinkError} if the library is not found or the given function name is not found within the library.

getName

public String getName()

getCallingConvention

public int getCallingConvention()

invoke

public Object invoke(Class returnType,
                     Object[] inArgs)
Invoke the native function with the given arguments, returning the native result as an Object.


invoke

public Object invoke(Class returnType,
                     Object[] inArgs,
                     Map options)
Invoke the native function with the given arguments, returning the native result as an Object.


invoke

Object invoke(Object[] args,
              Class returnType)
See Also:
implementation

invoke

public void invoke(Object[] args)
Call the native function being represented by this object

Parameters:
args - Arguments to pass to the native function

toString

public String toString()
Provide a human-readable representation of this object.

Overrides:
toString in class Pointer

invokePointer

public Pointer invokePointer(Object[] args)
Convenience method for invoke(Pointer.class, args).


invokeString

public String invokeString(Object[] args,
                           boolean wide)
Convenience method for invoke(String.class, args) or invoke(WString.class, args)

Parameters:
args - Arguments passed to native function
wide - Whether the return value is of type wchar_t*; if false, the return value is of type char*.

invokeInt

public int invokeInt(Object[] args)
Convenience method for invoke(Integer.class, args).


invokeLong

public long invokeLong(Object[] args)
Convenience method for invoke(Long.class, args).


invokeFloat

public float invokeFloat(Object[] args)
Convenience method for invoke(Float.class, args).


invokeDouble

public double invokeDouble(Object[] args)
Convenience method for invoke(Double.class, args).


invokeVoid

public void invokeVoid(Object[] args)
Convenience method for invoke(Void.class, args).


equals

public boolean equals(Object o)
Two function pointers are equal if they share the same peer address and calling convention.

Overrides:
equals in class Pointer
Parameters:
o - A Pointer instance
Returns:
True if the other object is a Pointer, and the C pointers being pointed to by these objects are also equal. Returns false otherwise.

concatenateVarArgs

static Object[] concatenateVarArgs(Object[] inArgs)
Concatenate varargs with normal args to obtain a simple argument array.


isVarArgs

static boolean isVarArgs(Method m)
Varargs are only supported on 1.5+.


valueOf

static Boolean valueOf(boolean b)
Implementation of Boolean.valueOf for older VMs.


JNA API 3.0.9

Copyright © 2007-2008 Timothy Wall. All Rights Reserved.