Top Description Inners Fields Constructors Methods
com.sun.jna

public Class Function

extends Pointer
Class Inheritance
Imports
java.lang.reflect.Method, java.util.Collections, .Map

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.

Function call behavior may be modified by passing one of the following call flags:
Authors
Sheng Liang, originator, Todd Fast, suitability modifications, Timothy Wall
See Also
Pointer

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
public static interface
Function.PostCallRead

Any argument which implements this interface will have the read method called immediately after function invocation.

Field Summary

Modifier and TypeField and Description
public static final int
ALT_CONVENTION

First alternate convention (currently used only for w32 stdcall).

public static final int
C_CONVENTION

Standard C calling convention.

pack-priv final int
pack-priv final String
private final String
pack-priv static final Integer
pack-priv static final Integer
private static final VarArgsChecker
IS_VARARGS

For checking if methods declare varargs

private NativeLibrary
private static final int
public static final int
MAX_NARGS

Maximum number of arguments supported by a JNA function call.

pack-priv static final String
OPTION_INVOKING_METHOD

For internal JNA use.

pack-priv final Map<String, ?>
public static final int
THROW_LAST_ERROR

Whether to throw an exception if last error is non-zero after call.

public static final int
USE_VARARGS

Mask for number of fixed args (max 255) for varargs calls.

private static final int
USE_VARARGS_SHIFT

Offset of USE_VARARGS in call flags

Inherited from com.sun.jna.Pointer:
NULLpeer

Constructor Summary

AccessConstructor and Description
pack-priv
Function(NativeLibrary
NativeLibrary in which to find the function
library
,
String
Name of the native function to be linked with
functionName
,
int
Function call flags
callFlags
,
String
Encoding for conversion between Java and native strings.
encoding
)

Create a new Function that is linked with a native function that follows the given calling convention.

pack-priv
Function(Pointer
Address of the native function
functionAddress
,
int
Function call flags
callFlags
,
String
Encoding for conversion between Java and native strings.
encoding
)

Create a new Function that is linked with a native function that follows the given calling convention.

Method Summary

Modifier and TypeMethod and Description
private void
checkCallingConvention(int convention)

pack-priv static Object[]
concatenateVarArgs(Object[] inArgs)

Concatenate varargs with normal args to obtain a simple argument array.

private Object
convertArgument(Object[] args, int index, Method invokingMethod, TypeMapper mapper, boolean allowObjects, Class<?> expectedType)

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides com.sun.jna.Pointer.equals.

Two function pointers are equal if they share the same peer address and calling convention.
pack-priv static int
fixedArgs(Method m)

Varargs are only supported on 1.5+.

public int
public static Function
getFunction(String
Library in which to find the native function
libraryName
,
String
Name of the native function to be linked with
functionName
)

Obtain a Function representing a native function that follows the standard "C" calling convention.

public static Function
getFunction(String
Library in which to find the function
libraryName
,
String
Name of the native function to be linked with
functionName
,
int
Function call flags
callFlags
)

Obtain a Function representing a native function.

public static Function
getFunction(String
Library in which to find the function
libraryName
,
String
Name of the native function to be linked with
functionName
,
int
Function call flags
callFlags
,
String
Encoding to use for conversion between Java and native strings.
encoding
)

Obtain a Function representing a native function.

public static Function
getFunction(Pointer
Native function pointer
p
)

Obtain a Function representing a native function pointer.

public static Function
getFunction(Pointer
Native function pointer
p
,
int
Function call flags
callFlags
)

Obtain a Function representing a native function pointer.

public static Function
getFunction(Pointer
Native function pointer
p
,
int
Function call flags
callFlags
,
String
Encoding to use for conversion between Java and native strings.
encoding
)

Obtain a Function representing a native function pointer.

public String
public int
hashCode()

Overrides com.sun.jna.Pointer.hashCode.

Provide a unique hash code for Functions which are equivalent.
public Object
invoke(Class<?> returnType, Object[] inArgs)

Invoke the native function with the given arguments, returning the native result as an Object.

public Object
invoke(Class<?> returnType, Object[] inArgs, Map<String, ?> options)

Invoke the native function with the given arguments, returning the native result as an Object.

pack-priv Object
invoke(Method invokingMethod, Class<?>[] paramTypes, Class<?> returnType, Object[] inArgs, Map<String, ?> options)

Invoke the native function with the given arguments, returning the native result as an Object.

pack-priv Object
invoke(Object[] args, Class<?> returnType, boolean allowObjects)

pack-priv Object
invoke(Object[] args, Class<?> returnType, boolean allowObjects, int fixedArgs)

public void
invoke(Object[]
Arguments to pass to the native function
args
)

Call the native function being represented by this object

public double
invokeDouble(Object[] args)

Convenience method for invoke(Double.class, args).

public float
invokeFloat(Object[] args)

Convenience method for invoke(Float.class, args).

public int
invokeInt(Object[] args)

Convenience method for invoke(Integer.class, args).

public long
invokeLong(Object[] args)

Convenience method for invoke(Long.class, args).

public Object
invokeObject(Object[] args)

Convenience method for invokeObject(Object.class, args).

private Pointer
invokePointer(int callFlags, Object[] args)

public Pointer
invokePointer(Object[] args)

Convenience method for invoke(Pointer.class, args).

private String

Returns:

The value returned by the target native function, as a String
invokeString
(int
calling convention to be used
callFlags
,
Object[]
Arguments to pass to the native function
args
,
boolean
whether the native string uses wchar_t; if false, char is assumed
wide
)

Call the native function being represented by this object

public String
invokeString(Object[]
Arguments passed to native function
args
,
boolean
Whether the return value is of type wchar_t*; if false, the return value is of type char*.
wide
)

Convenience method for invoke(String.class, args) or invoke(WString.class, args)

public void
invokeVoid(Object[] args)

Convenience method for invoke(Void.class, args).

private boolean
isPrimitiveArray(Class<?> argClass)

pack-priv static boolean
isVarArgs(Method m)

Varargs are only supported on 1.5+.

public String
toString()

Overrides com.sun.jna.Pointer.toString.

Provide a human-readable representation of this object.
pack-priv static Boolean
valueOf(boolean b)

Implementation of Boolean.valueOf for older VMs.

Inherited from com.sun.jna.Pointer:
clearcreateConstantcreateConstantdumpgetBytegetByteArraygetByteBuffergetChargetCharArraygetDoublegetDoubleArraygetFloatgetFloatArraygetIntgetIntArraygetLonggetLongArraygetNativeLonggetPointergetPointerArraygetPointerArraygetShortgetShortArraygetStringgetStringgetStringArraygetStringArraygetStringArraygetStringArraygetValuegetWideStringgetWideStringArraygetWideStringArrayindexOfnativeValuenativeValuereadreadreadreadreadreadreadreadsetBytesetCharsetDoublesetFloatsetIntsetLongsetMemorysetNativeLongsetPointersetShortsetStringsetStringsetStringsetValuesetWideStringsharesharewritewritewritewritewritewritewritewrite

Field Detail

ALT_CONVENTIONback to summary
public static final int ALT_CONVENTION

First alternate convention (currently used only for w32 stdcall).

Annotations
@Native
C_CONVENTIONback to summary
public static final int C_CONVENTION

Standard C calling convention.

Annotations
@Native
callFlagsback to summary
pack-priv final int callFlags
encodingback to summary
pack-priv final String encoding
functionNameback to summary
private final String functionName
INTEGER_FALSEback to summary
pack-priv static final Integer INTEGER_FALSE
INTEGER_TRUEback to summary
pack-priv static final Integer INTEGER_TRUE
IS_VARARGSback to summary
private static final VarArgsChecker IS_VARARGS

For checking if methods declare varargs

libraryback to summary
private NativeLibrary library
MASK_CCback to summary
private static final int MASK_CC
Annotations
@Native
MAX_NARGSback to summary
public static final int MAX_NARGS

Maximum number of arguments supported by a JNA function call.

Annotations
@Native
OPTION_INVOKING_METHODback to summary
pack-priv static final String OPTION_INVOKING_METHOD

For internal JNA use.

optionsback to summary
pack-priv final Map<String, ?> options
THROW_LAST_ERRORback to summary
public static final int THROW_LAST_ERROR

Whether to throw an exception if last error is non-zero after call.

Annotations
@Native
USE_VARARGSback to summary
public static final int USE_VARARGS

Mask for number of fixed args (max 255) for varargs calls.

Annotations
@Native
USE_VARARGS_SHIFTback to summary
private static final int USE_VARARGS_SHIFT

Offset of USE_VARARGS in call flags

Annotations
@Native

Constructor Detail

Functionback to summary
pack-priv Function(NativeLibrary library, String functionName, int callFlags, String encoding)

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

NativeLibrary in which to find the function

functionName:String

Name of the native function to be linked with

callFlags:int

Function call flags

encoding:String

Encoding for conversion between Java and native strings.

Exceptions
UnsatisfiedLinkError:
if the given function name is not found within the library.
Functionback to summary
pack-priv Function(Pointer functionAddress, int callFlags, String encoding)

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:Pointer

Address of the native function

callFlags:int

Function call flags

encoding:String

Encoding for conversion between Java and native strings.

Method Detail

checkCallingConventionback to summary
private void checkCallingConvention(int convention) throws IllegalArgumentException
concatenateVarArgsback to summary
pack-priv static Object[] concatenateVarArgs(Object[] inArgs)

Concatenate varargs with normal args to obtain a simple argument array.

convertArgumentback to summary
private Object convertArgument(Object[] args, int index, Method invokingMethod, TypeMapper mapper, boolean allowObjects, Class<?> expectedType)
equalsback to summary
public boolean equals(Object o)

Overrides com.sun.jna.Pointer.equals.

Two function pointers are equal if they share the same peer address and calling convention.

Parameters
o:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
fixedArgsback to summary
pack-priv static int fixedArgs(Method m)

Varargs are only supported on 1.5+.

getCallingConventionback to summary
public int getCallingConvention()
getFunctionback to summary
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:String

Library in which to find the native function

functionName:String

Name of the native function to be linked with

Exceptions
UnsatisfiedLinkError:
if the library is not found or the given function name is not found within the library.
getFunctionback to summary
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:String

Library in which to find the function

functionName:String

Name of the native function to be linked with

callFlags:int

Function call flags

Exceptions
UnsatisfiedLinkError:
if the library is not found or the given function name is not found within the library.
getFunctionback to summary
public static Function getFunction(String libraryName, String functionName, int callFlags, String encoding)

Obtain a Function representing a native function.

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

Parameters
libraryName:String

Library in which to find the function

functionName:String

Name of the native function to be linked with

callFlags:int

Function call flags

encoding:String

Encoding to use for conversion between Java and native strings.

Exceptions
UnsatisfiedLinkError:
if the library is not found or the given function name is not found within the library.
getFunctionback to summary
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:Pointer

Native function pointer

getFunctionback to summary
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:Pointer

Native function pointer

callFlags:int

Function call flags

getFunctionback to summary
public static Function getFunction(Pointer p, int callFlags, String encoding)

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:Pointer

Native function pointer

callFlags:int

Function call flags

encoding:String

Encoding to use for conversion between Java and native strings.

getNameback to summary
public String getName()
hashCodeback to summary
public int hashCode()

Overrides com.sun.jna.Pointer.hashCode.

Provide a unique hash code for Functions which are equivalent.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object.

Annotations
@Override
invokeback to summary
public Object invoke(Class<?> returnType, Object[] inArgs)

Invoke the native function with the given arguments, returning the native result as an Object.

invokeback to summary
public Object invoke(Class<?> returnType, Object[] inArgs, Map<String, ?> options)

Invoke the native function with the given arguments, returning the native result as an Object.

invokeback to summary
pack-priv Object invoke(Method invokingMethod, Class<?>[] paramTypes, Class<?> returnType, Object[] inArgs, Map<String, ?> options)

Invoke the native function with the given arguments, returning the native result as an Object. This method can be called if invoking method and parameter types are already at hand. When calling Function#invoke(Class, Object[], Map), the method has to be in the options under key Function#OPTION_INVOKING_METHOD.

invokeback to summary
pack-priv Object invoke(Object[] args, Class<?> returnType, boolean allowObjects)
invokeback to summary
pack-priv Object invoke(Object[] args, Class<?> returnType, boolean allowObjects, int fixedArgs)
invokeback to summary
public void invoke(Object[] args)

Call the native function being represented by this object

Parameters
args:Object[]

Arguments to pass to the native function

invokeDoubleback to summary
public double invokeDouble(Object[] args)

Convenience method for invoke(Double.class, args).

invokeFloatback to summary
public float invokeFloat(Object[] args)

Convenience method for invoke(Float.class, args).

invokeIntback to summary
public int invokeInt(Object[] args)

Convenience method for invoke(Integer.class, args).

invokeLongback to summary
public long invokeLong(Object[] args)

Convenience method for invoke(Long.class, args).

invokeObjectback to summary
public Object invokeObject(Object[] args)

Convenience method for invokeObject(Object.class, args).

invokePointerback to summary
private Pointer invokePointer(int callFlags, Object[] args)
invokePointerback to summary
public Pointer invokePointer(Object[] args)

Convenience method for invoke(Pointer.class, args).

invokeStringback to summary
private String invokeString(int callFlags, Object[] args, boolean wide)

Call the native function being represented by this object

Parameters
callFlags:int

calling convention to be used

args:Object[]

Arguments to pass to the native function

wide:boolean

whether the native string uses wchar_t; if false, char is assumed

Returns:String

The value returned by the target native function, as a String

invokeStringback to summary
public String invokeString(Object[] args, boolean wide)

Convenience method for invoke(String.class, args) or invoke(WString.class, args)

Parameters
args:Object[]

Arguments passed to native function

wide:boolean

Whether the return value is of type wchar_t*; if false, the return value is of type char*.

invokeVoidback to summary
public void invokeVoid(Object[] args)

Convenience method for invoke(Void.class, args).

isPrimitiveArrayback to summary
private boolean isPrimitiveArray(Class<?> argClass)
isVarArgsback to summary
pack-priv static boolean isVarArgs(Method m)

Varargs are only supported on 1.5+.

toStringback to summary
public String toString()

Overrides com.sun.jna.Pointer.toString.

Provide a human-readable representation of this object.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
valueOfback to summary
pack-priv static Boolean valueOf(boolean b)

Implementation of Boolean.valueOf for older VMs.

com.sun.jna back to summary

private Class Function.NativeMappedArray

extends Memory
implements PostCallRead
Class Inheritance
All Implemented Interfaces
com.sun.jna.Function.PostCallRead

Field Summary

Modifier and TypeField and Description
private final NativeMapped[]
Inherited from com.sun.jna.Memory:
size

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
read()

Implements com.sun.jna.Function.PostCallRead.read.

Perform any necessary post-call synchronization.
Inherited from com.sun.jna.Memory:
alignboundsCheckclearclosedisposedisposeAlldumpfreegetBytegetByteBuffergetChargetDoublegetFloatgetIntgetLonggetPointergetShortgetStringgetWideStringmallocpurgereadreadreadreadreadreadreadreadsetBytesetCharsetDoublesetFloatsetIntsetLongsetPointersetShortsetStringsetWideStringsharesharesizetoStringvalidwritewritewritewritewritewritewritewrite

Field Detail

originalback to summary
private final NativeMapped[] original

Constructor Detail

NativeMappedArrayback to summary
public NativeMappedArray(NativeMapped[] arg)

Method Detail

readback to summary
public void read()

Implements com.sun.jna.Function.PostCallRead.read.

Doc from com.sun.jna.Function.PostCallRead.read.

Perform any necessary post-call synchronization. Normally this just means reading from native memory any changes made by the native function call.

Annotations
@Override
com.sun.jna back to summary

private Class Function.PointerArray

extends Memory
implements PostCallRead
Class Inheritance
All Implemented Interfaces
com.sun.jna.Function.PostCallRead

Field Summary

Modifier and TypeField and Description
private final Pointer[]
Inherited from com.sun.jna.Memory:
size

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
read()

Implements com.sun.jna.Function.PostCallRead.read.

Perform any necessary post-call synchronization.
Inherited from com.sun.jna.Memory:
alignboundsCheckclearclosedisposedisposeAlldumpfreegetBytegetByteBuffergetChargetDoublegetFloatgetIntgetLonggetPointergetShortgetStringgetWideStringmallocpurgereadreadreadreadreadreadreadreadsetBytesetCharsetDoublesetFloatsetIntsetLongsetPointersetShortsetStringsetWideStringsharesharesizetoStringvalidwritewritewritewritewritewritewritewrite

Field Detail

originalback to summary
private final Pointer[] original

Constructor Detail

PointerArrayback to summary
public PointerArray(Pointer[] arg)

Method Detail

readback to summary
public void read()

Implements com.sun.jna.Function.PostCallRead.read.

Doc from com.sun.jna.Function.PostCallRead.read.

Perform any necessary post-call synchronization. Normally this just means reading from native memory any changes made by the native function call.

Annotations
@Override
com.sun.jna back to summary

public Interface Function.PostCallRead

Known Direct Implementers
com.sun.jna.Function.NativeMappedArray, com.sun.jna.Function.PointerArray, com.sun.jna.StringArray

Any argument which implements this interface will have the read method called immediately after function invocation.

Method Summary

Modifier and TypeMethod and Description
public void
read()

Perform any necessary post-call synchronization.

Method Detail

readback to summary
public void read()

Perform any necessary post-call synchronization. Normally this just means reading from native memory any changes made by the native function call.