Class Function
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. 
- C_CONVENTIONUse C calling convention (default)
- ALT_CONVENTIONUse alternate calling convention (e.g. stdcall)
- THROW_LAST_ERRORThrow a- LastErrorExceptionif the native function sets the system error to a non-zero value (errno or GetLastError). Setting this flag will cause the system error to be cleared prior to native function invocation.
- Author:
- Sheng Liang, originator, Todd Fast, suitability modifications, Timothy Wall
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceAny argument which implements this interface will have theFunction.PostCallRead.read()method called immediately after function invocation.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intFirst alternate convention (currently used only for w32 stdcall).static final intStandard C calling convention.(package private) final int(package private) final String(package private) static final Integer(package private) static final Integerstatic final intMaximum number of arguments supported by a JNA function call.(package private) static final StringFor internal JNA use.static final intWhether to throw an exception if last error is non-zero after call.static final intMask for number of fixed args (1-3) for varargs calls.
- 
Constructor SummaryConstructorsConstructorDescriptionFunction(NativeLibrary library, String functionName, int callFlags, String encoding) Create a newFunctionthat is linked with a native function that follows the given calling convention.Create a newFunctionthat is linked with a native function that follows the given calling convention.
- 
Method SummaryModifier and TypeMethodDescription(package private) static Object[]concatenateVarArgs(Object[] inArgs) Concatenate varargs with normal args to obtain a simple argument array.booleanTwo function pointers are equal if they share the same peer address and calling convention.(package private) static intVarargs are only supported on 1.5+.intstatic FunctionObtain aFunctionrepresenting a native function pointer.static FunctiongetFunction(Pointer p, int callFlags) Obtain aFunctionrepresenting a native function pointer.static FunctiongetFunction(Pointer p, int callFlags, String encoding) Obtain aFunctionrepresenting a native function pointer.static FunctiongetFunction(String libraryName, String functionName) Obtain aFunctionrepresenting a native function that follows the standard "C" calling convention.static FunctiongetFunction(String libraryName, String functionName, int callFlags) Obtain aFunctionrepresenting a native function.static FunctiongetFunction(String libraryName, String functionName, int callFlags, String encoding) Obtain aFunctionrepresenting a native function.getName()inthashCode()Provide a unique hash code forFunctions which are equivalent.Invoke the native function with the given arguments, returning the native result as an Object.Invoke the native function with the given arguments, returning the native result as an Object.voidCall the native function being represented by this object(package private) Object(package private) Object(package private) Objectinvoke(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.doubleinvokeDouble(Object[] args) Convenience method forinvoke(Double.class, args).floatinvokeFloat(Object[] args) Convenience method forinvoke(Float.class, args).intConvenience method forinvoke(Integer.class, args).longinvokeLong(Object[] args) Convenience method forinvoke(Long.class, args).invokeObject(Object[] args) Convenience method forinvokeObject(Object.class, args).invokePointer(Object[] args) Convenience method forinvoke(Pointer.class, args).invokeString(Object[] args, boolean wide) Convenience method forinvoke(String.class, args)orinvoke(WString.class, args)voidinvokeVoid(Object[] args) Convenience method forinvoke(Void.class, args).(package private) static booleanVarargs are only supported on 1.5+.toString()Provide a human-readable representation of this object.(package private) static BooleanvalueOf(boolean b) Implementation of Boolean.valueOf for older VMs.Methods inherited from class com.sun.jna.Pointerclear, createConstant, createConstant, dump, getByte, getByteArray, getByteBuffer, getChar, getCharArray, getDouble, getDoubleArray, getFloat, getFloatArray, getInt, getIntArray, getLong, getLongArray, getNativeLong, getPointer, getPointerArray, getPointerArray, getShort, getShortArray, getString, getString, getStringArray, getStringArray, getStringArray, getStringArray, getValue, getWideString, getWideStringArray, getWideStringArray, indexOf, nativeValue, nativeValue, read, read, read, read, read, read, read, read, setByte, setChar, setDouble, setFloat, setInt, setLong, setMemory, setNativeLong, setPointer, setShort, setString, setString, setString, setValue, setWideString, share, share, write, write, write, write, write, write, write, write
- 
Field Details- 
MAX_NARGSMaximum number of arguments supported by a JNA function call.- See Also:
 
- 
C_CONVENTIONStandard C calling convention.- See Also:
 
- 
ALT_CONVENTIONFirst alternate convention (currently used only for w32 stdcall).- See Also:
 
- 
THROW_LAST_ERRORWhether to throw an exception if last error is non-zero after call.- See Also:
 
- 
USE_VARARGSMask for number of fixed args (1-3) for varargs calls.- See Also:
 
- 
INTEGER_TRUE
- 
INTEGER_FALSE
- 
encoding
- 
callFlagsfinal int callFlags
- 
options
- 
OPTION_INVOKING_METHODFor internal JNA use.- See Also:
 
 
- 
- 
Constructor Details- 
FunctionFunction(NativeLibrary library, String functionName, int callFlags, String encoding) Create a newFunctionthat 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-- NativeLibraryin which to find the function
- functionName- Name of the native function to be linked with
- callFlags- Function call flags
- encoding- Encoding for conversion between Java and native strings.
- Throws:
- UnsatisfiedLinkError- if the given function name is not found within the library.
 
- 
FunctionCreate a newFunctionthat 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
- encoding- Encoding for conversion between Java and native strings.
 
 
- 
- 
Method Details- 
getFunctionObtain aFunctionrepresenting 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.
 
- 
getFunctionObtain aFunctionrepresenting 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.
 
- 
getFunctionpublic static Function getFunction(String libraryName, String functionName, int callFlags, String encoding) Obtain aFunctionrepresenting 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
- encoding- Encoding to use for conversion between Java and native strings.
- Throws:
- UnsatisfiedLinkError- if the library is not found or the given function name is not found within the library.
 
- 
getFunctionObtain aFunctionrepresenting 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
 
- 
getFunctionObtain aFunctionrepresenting 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
 
- 
getFunctionObtain aFunctionrepresenting 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
- encoding- Encoding to use for conversion between Java and native strings.
 
- 
getName
- 
getCallingConventionpublic int getCallingConvention()
- 
invokeInvoke the native function with the given arguments, returning the native result as an Object.
- 
invokeInvoke the native function with the given arguments, returning the native result as an Object.
- 
invokeObject 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 callinginvoke(Class, Object[], Map), the method has to be in the options under keyOPTION_INVOKING_METHOD.
- 
invoke
- 
invoke
- 
invokeCall the native function being represented by this object- Parameters:
- args- Arguments to pass to the native function
 
- 
toStringProvide a human-readable representation of this object.
- 
invokeObjectConvenience method forinvokeObject(Object.class, args).
- 
invokePointerConvenience method forinvoke(Pointer.class, args).
- 
invokeStringConvenience method forinvoke(String.class, args)orinvoke(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*.
 
- 
invokeIntConvenience method forinvoke(Integer.class, args).
- 
invokeLongConvenience method forinvoke(Long.class, args).
- 
invokeFloatConvenience method forinvoke(Float.class, args).
- 
invokeDoubleConvenience method forinvoke(Double.class, args).
- 
invokeVoidConvenience method forinvoke(Void.class, args).
- 
equalsTwo function pointers are equal if they share the same peer address and calling convention.
- 
hashCodepublic int hashCode()Provide a unique hash code forFunctions which are equivalent.
- 
concatenateVarArgsConcatenate varargs with normal args to obtain a simple argument array.
- 
isVarArgsVarargs are only supported on 1.5+.
- 
fixedArgsVarargs are only supported on 1.5+.
- 
valueOfImplementation of Boolean.valueOf for older VMs.
 
-