com.sun.jna

Class Function

public class Function extends Pointer

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

Function call behavior may be modified by passing one of the following call flags:

Author: Sheng Liang, originator Todd Fast, suitability modifications Timothy Wall

See Also: Pointer

Nested Class Summary
interfaceFunction.PostCallRead
Any argument which implements this interface will have the PostCallRead method called immediately after function invocation.
Field Summary
static intALT_CONVENTION
First alternate convention (currently used only for w32 stdcall).
intcallFlags
static intC_CONVENTION
Standard C calling convention.
static IntegerINTEGER_FALSE
static IntegerINTEGER_TRUE
static intMAX_NARGS
Maximum number of arguments supported by a JNA function call.
Mapoptions
static StringOPTION_INVOKING_METHOD
For internal JNA use.
static intTHROW_LAST_ERROR
Whether to throw an exception if last error is non-zero after call.
Constructor Summary
Function(NativeLibrary library, String functionName, int callFlags)
Create a new Function that is linked with a native function that follows the given calling convention.
Function(Pointer functionAddress, int callFlags)
Create a new Function that is linked with a native function that follows the given calling convention.
Method Summary
static Object[]concatenateVarArgs(Object[] inArgs)
Concatenate varargs with normal args to obtain a simple argument array.
booleanequals(Object o)
Two function pointers are equal if they share the same peer address and calling convention.
intgetCallingConvention()
static FunctiongetFunction(String libraryName, String functionName)
Obtain a Function representing a native function that follows the standard "C" calling convention.
static FunctiongetFunction(String libraryName, String functionName, int callFlags)
Obtain a Function representing a native function.
static FunctiongetFunction(Pointer p)
Obtain a Function representing a native function pointer.
static FunctiongetFunction(Pointer p, int callFlags)
Obtain a Function representing a native function pointer.
StringgetName()
Objectinvoke(Class returnType, Object[] inArgs)
Invoke the native function with the given arguments, returning the native result as an Object.
Objectinvoke(Class returnType, Object[] inArgs, Map options)
Invoke the native function with the given arguments, returning the native result as an Object.
Objectinvoke(Object[] args, Class returnType, boolean allowObjects)
voidinvoke(Object[] args)
Call the native function being represented by this object
doubleinvokeDouble(Object[] args)
floatinvokeFloat(Object[] args)
intinvokeInt(Object[] args)
longinvokeLong(Object[] args)
ObjectinvokeObject(Object[] args)
PointerinvokePointer(Object[] args)
StringinvokeString(Object[] args, boolean wide)
voidinvokeVoid(Object[] args)
static booleanisVarArgs(Method m)
Varargs are only supported on 1.5+.
StringtoString()
Provide a human-readable representation of this object.
static BooleanvalueOf(boolean b)
Implementation of Boolean.valueOf for older VMs.

Field Detail

ALT_CONVENTION

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

callFlags

int callFlags

C_CONVENTION

public static final int C_CONVENTION
Standard C calling convention.

INTEGER_FALSE

static final Integer INTEGER_FALSE

INTEGER_TRUE

static final Integer INTEGER_TRUE

MAX_NARGS

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

options

final Map options

OPTION_INVOKING_METHOD

static final String OPTION_INVOKING_METHOD
For internal JNA use.

THROW_LAST_ERROR

public static final int THROW_LAST_ERROR
Whether to throw an exception if last error is non-zero after call.

Constructor Detail

Function

Function(NativeLibrary library, String functionName, int callFlags)
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 callFlags Function call flags

Throws: UnsatisfiedLinkError if the given function name is not found within the library.

Function

Function(Pointer functionAddress, int callFlags)
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 callFlags Function call flags

Method Detail

concatenateVarArgs

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

equals

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

getCallingConvention

public int getCallingConvention()

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: 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 callFlags)
Obtain a Function representing a native function.

The allocated instance represents a pointer to the named native function from the named library.

Parameters: libraryName Library in which to find the function functionName Name of the native function to be linked with callFlags Function call flags

Throws: UnsatisfiedLinkError if the library is not found or the given function name is not found within the library.

getFunction

public static Function getFunction(Pointer p)
Obtain a Function representing a native function pointer. In general, this function should be used by dynamic languages; Java code should allow JNA to bind to a specific Callback interface instead by defining a return type or Structure field type.

The allocated instance represents a pointer to the native function pointer.

Parameters: p Native function pointer

getFunction

public static Function getFunction(Pointer p, int callFlags)
Obtain a Function representing a native function pointer. In general, this function should be used by dynamic languages; Java code should allow JNA to bind to a specific Callback interface instead by defining a return type or Structure field type.

The allocated instance represents a pointer to the native function pointer.

Parameters: p Native function pointer callFlags Function call flags

getName

public String getName()

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, boolean allowObjects)

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

invokeDouble

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

invokeFloat

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

invokeInt

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

invokeLong

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

invokeObject

public Object invokeObject(Object[] args)
Convenience method for (Class,Object[]) invokeObject(Object.class, args).

invokePointer

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

invokeString

public String invokeString(Object[] args, boolean wide)
Convenience method for (Class,Object[]) invoke(String.class, args) or (Class,Object[]) 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*.

invokeVoid

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

isVarArgs

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

toString

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

valueOf

static Boolean valueOf(boolean b)
Implementation of Boolean.valueOf for older VMs.
Copyright © 2007-2009 Timothy Wall. All Rights Reserved.