Klasse 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_CONVENTION
Use C calling convention (default)ALT_CONVENTION
Use alternate calling convention (e.g. stdcall)THROW_LAST_ERROR
Throw aLastErrorException
if 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.
- Autor:
- Sheng Liang, originator, Todd Fast, suitability modifications, Timothy Wall
- Siehe auch:
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypKlasseBeschreibungstatic interface
Any argument which implements this interface will have theFunction.PostCallRead.read()
method called immediately after function invocation. -
Feldübersicht
FelderModifizierer und TypFeldBeschreibungstatic final int
First alternate convention (currently used only for w32 stdcall).static final int
Standard C calling convention.(Package privat) final int
(Package privat) final String
(Package privat) static final Integer
(Package privat) static final Integer
static final int
Maximum number of arguments supported by a JNA function call.(Package privat) static final String
For internal JNA use.static final int
Whether to throw an exception if last error is non-zero after call.static final int
Mask for number of fixed args (max 255) for varargs calls. -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungFunction
(NativeLibrary library, String functionName, int callFlags, String encoding) Create a newFunction
that is linked with a native function that follows the given calling convention.Create a newFunction
that is linked with a native function that follows the given calling convention. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibung(Package privat) static Object[]
concatenateVarArgs
(Object[] inArgs) Concatenate varargs with normal args to obtain a simple argument array.boolean
Two function pointers are equal if they share the same peer address and calling convention.(Package privat) static int
Varargs are only supported on 1.5+.int
static Function
Obtain aFunction
representing a native function pointer.static Function
getFunction
(Pointer p, int callFlags) Obtain aFunction
representing a native function pointer.static Function
getFunction
(Pointer p, int callFlags, String encoding) Obtain aFunction
representing a native function pointer.static Function
getFunction
(String libraryName, String functionName) Obtain aFunction
representing a native function that follows the standard "C" calling convention.static Function
getFunction
(String libraryName, String functionName, int callFlags) Obtain aFunction
representing a native function.static Function
getFunction
(String libraryName, String functionName, int callFlags, String encoding) Obtain aFunction
representing a native function.getName()
int
hashCode()
Provide a unique hash code forFunction
s 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.void
Call the native function being represented by this object(Package privat) Object
(Package privat) Object
(Package privat) 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.double
invokeDouble
(Object[] args) Convenience method forinvoke(Double.class, args)
.float
invokeFloat
(Object[] args) Convenience method forinvoke(Float.class, args)
.int
Convenience method forinvoke(Integer.class, args)
.long
invokeLong
(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)
void
invokeVoid
(Object[] args) Convenience method forinvoke(Void.class, args)
.(Package privat) static boolean
Varargs are only supported on 1.5+.toString()
Provide a human-readable representation of this object.(Package privat) static Boolean
valueOf
(boolean b) Implementation of Boolean.valueOf for older VMs.Von Klasse geerbte Methoden com.sun.jna.Pointer
clear, 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
-
Felddetails
-
MAX_NARGS
Maximum number of arguments supported by a JNA function call.- Siehe auch:
-
C_CONVENTION
Standard C calling convention.- Siehe auch:
-
ALT_CONVENTION
First alternate convention (currently used only for w32 stdcall).- Siehe auch:
-
THROW_LAST_ERROR
Whether to throw an exception if last error is non-zero after call.- Siehe auch:
-
USE_VARARGS
Mask for number of fixed args (max 255) for varargs calls.- Siehe auch:
-
INTEGER_TRUE
-
INTEGER_FALSE
-
encoding
-
callFlags
final int callFlags -
options
-
OPTION_INVOKING_METHOD
For internal JNA use.- Siehe auch:
-
-
Konstruktordetails
-
Function
Function(NativeLibrary library, String functionName, int callFlags, String encoding) Create a newFunction
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.
- Parameter:
library
-NativeLibrary
in which to find the functionfunctionName
- Name of the native function to be linked withcallFlags
- Function call flagsencoding
- Encoding for conversion between Java and native strings.- Löst aus:
UnsatisfiedLinkError
- if the given function name is not found within the library.
-
Function
Create a newFunction
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.
- Parameter:
functionAddress
- Address of the native functioncallFlags
- Function call flagsencoding
- Encoding for conversion between Java and native strings.
-
-
Methodendetails
-
getFunction
Obtain aFunction
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.
- Parameter:
libraryName
- Library in which to find the native functionfunctionName
- Name of the native function to be linked with- Löst aus:
UnsatisfiedLinkError
- if the library is not found or the given function name is not found within the library.
-
getFunction
Obtain aFunction
representing a native function.The allocated instance represents a pointer to the named native function from the named library.
- Parameter:
libraryName
- Library in which to find the functionfunctionName
- Name of the native function to be linked withcallFlags
- Function call flags- Löst aus:
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, String encoding) Obtain aFunction
representing a native function.The allocated instance represents a pointer to the named native function from the named library.
- Parameter:
libraryName
- Library in which to find the functionfunctionName
- Name of the native function to be linked withcallFlags
- Function call flagsencoding
- Encoding to use for conversion between Java and native strings.- Löst aus:
UnsatisfiedLinkError
- if the library is not found or the given function name is not found within the library.
-
getFunction
Obtain aFunction
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.
- Parameter:
p
- Native function pointer
-
getFunction
Obtain aFunction
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.
- Parameter:
p
- Native function pointercallFlags
- Function call flags
-
getFunction
Obtain aFunction
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.
- Parameter:
p
- Native function pointercallFlags
- Function call flagsencoding
- Encoding to use for conversion between Java and native strings.
-
getName
-
getCallingConvention
public int getCallingConvention() -
invoke
Invoke the native function with the given arguments, returning the native result as an Object. -
invoke
Invoke the native function with the given arguments, returning the native result as an Object. -
invoke
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 callinginvoke(Class, Object[], Map)
, the method has to be in the options under keyOPTION_INVOKING_METHOD
. -
invoke
-
invoke
-
invoke
Call the native function being represented by this object- Parameter:
args
- Arguments to pass to the native function
-
toString
Provide a human-readable representation of this object. -
invokeObject
Convenience method forinvokeObject(Object.class, args)
. -
invokePointer
Convenience method forinvoke(Pointer.class, args)
. -
invokeString
Convenience method forinvoke(String.class, args)
orinvoke(WString.class, args)
- Parameter:
args
- Arguments passed to native functionwide
- Whether the return value is of typewchar_t*
; if false, the return value is of typechar*
.
-
invokeInt
Convenience method forinvoke(Integer.class, args)
. -
invokeLong
Convenience method forinvoke(Long.class, args)
. -
invokeFloat
Convenience method forinvoke(Float.class, args)
. -
invokeDouble
Convenience method forinvoke(Double.class, args)
. -
invokeVoid
Convenience method forinvoke(Void.class, args)
. -
equals
Two function pointers are equal if they share the same peer address and calling convention. -
hashCode
public int hashCode()Provide a unique hash code forFunction
s which are equivalent. -
concatenateVarArgs
Concatenate varargs with normal args to obtain a simple argument array. -
isVarArgs
Varargs are only supported on 1.5+. -
fixedArgs
Varargs are only supported on 1.5+. -
valueOf
Implementation of Boolean.valueOf for older VMs.
-