Class Native
- All Implemented Interfaces:
- Version
 getTypeMapper(java.lang.Class<?>) and getStructureAlignment(java.lang.Class<?>) are provided
 to avoid having to explicitly pass these parameters to Structures,
 which would require every Structure which requires custom mapping
 or alignment to define a constructor and pass parameters to the superclass.
 To avoid lots of boilerplate, the base Structure constructor
 figures out these properties based on its enclosing interface.
Library Loading
When JNA classes are loaded, the native shared library (jnidispatch) is
 loaded as well.  An attempt is made to load it from the any paths defined
 in jna.boot.library.path (if defined), then the system library
 path using System.loadLibrary(java.lang.String), unless jna.nosys=true.
 If not found, the appropriate library will be extracted from the class path
 (into a temporary directory if found within a jar file) and loaded from
 there, unless jna.noclasspath=true.  If your system has
 additional security constraints regarding execution or load of files
 (SELinux, for example), you should  probably install the native library in
 an accessible location and configure  your system accordingly, rather than
 relying on JNA to extract the library  from its own jar file.
To avoid the automatic unpacking (in situations where you want to force a
 failure if the JNA native library is not properly installed on the system),
 set the system property jna.nounpack=true.
 
While this class and its corresponding native library are loaded, the
 system property jna.loaded will be set.  The property will be
 cleared when native support has been unloaded (i.e. the Native class and
 its underlying native support has been GC'd).
NOTE: all native functions are provided within this class to ensure that all other JNA-provided classes and objects are GC'd and/or finalized/disposed before this class is disposed and/or removed from memory (most notably Memory and any other class which by default frees its resources in a finalizer).
Native Library Loading
Native libraries loaded viaload(Class) may be found in
 several locations.- Author:
- Todd Fast, todd.fast@sun.com, twall@users.sf.net
- See Also:
- 
Nested Class SummaryNested Classes
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intSize of a nativebooltype (C99 and later), in bytes.(package private) static final intIndicates whether the callback has an initializer.(package private) static final intUse direct mapping for callback.(package private) static final intReturn a DLL-resident fucntion pointer.static final booleanstatic final booleanstatic final Charsetstatic final String(package private) static final String(package private) static Stringstatic final intSize of a nativelong doubletype (C99 and later), in bytes.static final intSize of a nativelongtype, in bytes.(package private) static final int(package private) static final intstatic final intThe size of a native pointer (void*) on the current platform, in bytes.static final intSize of a nativesize_ttype, in bytes.static final intSize of a nativewchar_ttype, in bytes.Fields inherited from interface com.sun.jna.VersionVERSION, VERSION_NATIVE
- 
Method SummaryModifier and TypeMethodDescription(package private) static voidclose(long handle) Close the given native library.(package private) static longcreateNativeCallback(Callback callback, Method method, Class<?>[] parameterTypes, Class<?> returnType, int callingConvention, int flags, String encoding) Create a native trampoline to delegate execution to the Java callback.(package private) static booleandeleteLibrary(File lib) Remove any automatically unpacked native library.static voiddetach(boolean detach) Indicate whether the JVM should detach the current native thread when the current Java code finishes execution.static FileAttempt to extract a native library from the current resource path, using the current thread context class loader.static FileextractFromResourcePath(String name, ClassLoader loader) Attempt to extract a native library from the resource path using the given class loader.static voidffi_call(long cif, long fptr, long resp, long args) Make an FFI function call.static voidffi_free_closure(long closure) static longffi_prep_cif(int abi, int nargs, long ffi_return_type, long ffi_types) Create a new cif structure.static longffi_prep_closure(long cif, Native.ffi_callback cb) (package private) static Class<?>findDirectMappedClass(Class<?> cls) Find the nearest enclosing class with native methods.(package private) static Class<?>findEnclosingLibraryClass(Class<?> cls) Find the library interface corresponding to the given class.(package private) static longfindSymbol(long handle, String name) static voidfree(long ptr) Call the real native free(package private) static voidfreeNativeCallback(long ptr) Free the given callback trampoline.(package private) static byte(package private) static byte[](package private) static byte[](package private) static byte[](package private) static Class<?>Try to determine the class context in which aregister(String)call was made.(package private) static charstatic longUtility method to get the native window ID for a heavyweight JavaComponentas alongvalue.static Pointerstatic Stringstatic Pointer(package private) static ByteBuffergetDirectByteBuffer(Pointer pointer, long addr, long offset, long length) (package private) static double(package private) static float(package private) static intstatic intRetrieve last error set by the OS.getLibraryOptions(Class<?> type) Return the preferred native library configuration options for the given class.(package private) static longstatic intgetNativeSize(Class<?> cls) Returns the native size for a given Java class.static intgetNativeSize(Class<?> type, Object value) (package private) static PointergetPointer(long addr) (package private) static short(package private) static StringgetSignature(Class<?> cls) (package private) static String(package private) static String(package private) static byte[]getStringBytes(Pointer pointer, long baseaddr, long offset) static StringgetStringEncoding(Class<?> cls) static intgetStructureAlignment(Class<?> cls) (package private) static FileObtain a directory suitable for writing JNA-specific temporary files.(package private) static Pointerstatic TypeMappergetTypeMapper(Class<?> cls) Return the preferredTypeMapperfor the given native interface.static StringgetWebStartLibraryPath(String libName) If running web start, determine the location of a given native library.(package private) static StringgetWideString(Pointer pointer, long baseaddr, long offset) (package private) static longstatic longUtility method to get the native window ID for a JavaWindowas alongvalue.static Pointer(package private) static long(package private) static intinitialize_ffi_type(long type_info) Returns the size (calculated by libffi) of the given type.(package private) static doubleinvokeDouble(Function function, long fp, int callFlags, Object[] args) Call the native function.(package private) static floatinvokeFloat(Function function, long fp, int callFlags, Object[] args) Call the native function.(package private) static intCall the native function.(package private) static longinvokeLong(Function function, long fp, int callFlags, Object[] args) Call the native function.(package private) static ObjectinvokeObject(Function function, long fp, int callFlags, Object[] args) Call the native function, returning a JavaObject.(package private) static longinvokePointer(Function function, long fp, int callFlags, Object[] args) Call the native function.(package private) static StructureinvokeStructure(Function function, long fp, int callFlags, Object[] args, Structure s) Call the native function, returning a struct by value.(package private) static voidinvokeVoid(Function function, long fp, int callFlags, Object[] args) Call the native function.(package private) static booleanisCompatibleVersion(String expectedVersion, String nativeVersion) Version string must have the structure. . a bugfix change in the native code increments revision, the minor is incremented for backwards compatible changes and the major version is changed for backwards incompatbile changes. static booleanReturns whether protection is enabled.static booleanisSupportedNativeType(Class<?> cls) (package private) static booleanisUnpacked(File file) Identify temporary files unpacked from classpath jar files.static <T extends Library>
 TMap a library interface to the current process, providing the explicit interface class.static <T extends Library>
 TMap a library interface to the current process, providing the explicit interface class.static <T extends Library>
 TMap a library interface to the given shared library, providing the explicit interface class.static <T extends Library>
 TLoad a library interface from the given shared library, providing the explicit interface class and a map of options for the library.static <T> TloadLibrary(Class<T> interfaceClass) Deprecated.static <T> TloadLibrary(Class<T> interfaceClass, Map<String, ?> options) Deprecated.static <T> TloadLibrary(String name, Class<T> interfaceClass) Deprecated.static <T> TloadLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) Deprecated.static voidPrints JNA library details to the console.static longmalloc(long size) Call the real native malloc(package private) static voidmarkTemporaryFile(File file) Perform cleanup of automatically unpacked native shared library.(package private) static longOpen the requested native library with default options.(package private) static longOpen the requested native library with the specified platform-specific otions.(package private) static void(package private) static void(package private) static void(package private) static void(package private) static void(package private) static void(package private) static voidstatic voidregister(NativeLibrary lib) When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.static voidregister(Class<?> cls, NativeLibrary lib) When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.static voidWhen called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.static voidWhen called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.static booleanregistered(Class<?> cls) (package private) static voidRemove all marked temporary files in the given directory.(package private) static String(package private) static voidstatic voidSet the default handler invoked when a callback throws an uncaught exception.static voidsetCallbackThreadInitializer(Callback cb, CallbackThreadInitializer initializer) Set a thread initializer for the given callback.(package private) static void(package private) static void(package private) static void(package private) static voidstatic voidsetLastError(int code) Set the OS last error code.(package private) static void(package private) static void(package private) static voidsetPointer(Pointer pointer, long baseaddr, long offset, long value) static voidsetProtected(boolean enable) Set whether native memory accesses are protected from invalid accesses.(package private) static void(package private) static voidsetWideString(Pointer pointer, long baseaddr, long offset, String value) static LibrarysynchronizedLibrary(Library library) Returns a synchronized (thread-safe) library backed by the specified library.static byte[]static byte[]toByteArray(String s, String encoding) static byte[]toByteArray(String s, Charset charset) static char[]static StringtoString(byte[] buf) Obtain a Java String from the given native byte array.static StringObtain a Java String from the given native byte array, using the given encoding.static StringObtain a Java String from the given native byte array, using the given encoding.static StringtoString(char[] buf) Obtain a Java String from the given native wchar_t array.toStringList(char[] buf) toStringList(char[] buf, int offset, int len) static voidRemove all native mappings for the calling class.static voidunregister(Class<?> cls) Remove all native mappings for the given class.(package private) static void(package private) static void(package private) static void(package private) static void(package private) static void(package private) static void(package private) static void
- 
Field Details- 
DEFAULT_CHARSET
- 
DEFAULT_ENCODING
- 
DEBUG_LOADpublic static final boolean DEBUG_LOAD
- 
DEBUG_JNA_LOADpublic static final boolean DEBUG_JNA_LOAD
- 
jnidispatchPath
- 
POINTER_SIZEpublic static final int POINTER_SIZEThe size of a native pointer (void*) on the current platform, in bytes.
- 
LONG_SIZEpublic static final int LONG_SIZESize of a nativelongtype, in bytes.
- 
WCHAR_SIZEpublic static final int WCHAR_SIZESize of a nativewchar_ttype, in bytes.
- 
SIZE_T_SIZEpublic static final int SIZE_T_SIZESize of a nativesize_ttype, in bytes.
- 
BOOL_SIZEpublic static final int BOOL_SIZESize of a nativebooltype (C99 and later), in bytes.
- 
LONG_DOUBLE_SIZEpublic static final int LONG_DOUBLE_SIZESize of a nativelong doubletype (C99 and later), in bytes.
- 
MAX_ALIGNMENTstatic final int MAX_ALIGNMENT
- 
MAX_PADDINGstatic final int MAX_PADDING
- 
JNA_TMPLIB_PREFIX- See Also:
 
- 
CB_HAS_INITIALIZERstatic final int CB_HAS_INITIALIZERIndicates whether the callback has an initializer.- See Also:
 
- 
CB_OPTION_DIRECTstatic final int CB_OPTION_DIRECTUse direct mapping for callback.- See Also:
 
- 
CB_OPTION_IN_DLLstatic final int CB_OPTION_IN_DLLReturn a DLL-resident fucntion pointer.- See Also:
 
 
- 
- 
Method Details- 
isCompatibleVersionVersion string must have the structure. . a bugfix change in the native code increments revision, the minor is incremented for backwards compatible changes and the major version is changed for backwards incompatbile changes. - Parameters:
- expectedVersion-
- nativeVersion-
- Returns:
- true if nativeVersion describes a version compatible to expectedVersion
 
- 
deleteLibraryRemove any automatically unpacked native library. This will fail on windows, which disallows removal of any file that is still in use, so an alternative is required in that case. Mark the file that could not be deleted, and attempt to delete any temporaries on next startup. Do NOT force the class loader to unload the native library, since that introduces issues with cleaning up any extant JNA bits (e.g. Memory) which may still need use of the library before shutdown.
- 
setProtectedpublic static void setProtected(boolean enable) Set whether native memory accesses are protected from invalid accesses. This should only be set true when testing or debugging, and should not be considered reliable or robust for applications where JNA native calls are occurring on multiple threads. Protected mode will be automatically set if the system propertyjna.protectedhas a value of "true" when the JNA library is first loaded.If not supported by the underlying platform, this setting will have no effect. NOTE: On platforms which support signals (non-Windows), JNA uses signals to trap errors. This may interfere with the JVM's own use of signals. When protected mode is enabled, you should make use of the jsig library, if available (see Signal Chaining). In short, set the environment variable LD_PRELOADto the path tolibjsig.soin your JRE lib directory (usually ${java.home}/lib/${os.arch}/libjsig.so) before launching your Java application.
- 
isProtectedpublic static boolean isProtected()Returns whether protection is enabled. Check the result of this method after callingsetProtected(true)to determine if this platform supports protecting memory accesses.
- 
getWindowIDUtility method to get the native window ID for a JavaWindowas alongvalue. This method is primarily for X11-based systems, which use an opaqueXID(usuallylong int) to identify windows.- Throws:
- HeadlessException- if the current VM is running headless
 
- 
getComponentIDUtility method to get the native window ID for a heavyweight JavaComponentas alongvalue. This method is primarily for X11-based systems, which use an opaqueXID(usuallylong int) to identify windows.- Throws:
- HeadlessException- if the current VM is running headless
 
- 
getWindowPointerUtility method to get the native window pointer for a JavaWindowas aPointervalue. This method is primarily for w32, which uses theHANDLEtype (actuallyvoid *) to identify windows.- Throws:
- HeadlessException- if the current VM is running headless
 
- 
getComponentPointerUtility method to get the native window pointer for a heavyweight JavaComponentas aPointervalue. This method is primarily for w32, which uses theHWNDtype (actuallyvoid *) to identify windows.- Throws:
- HeadlessException- if the current VM is running headless
 
- 
getWindowHandle0
- 
getDirectBufferPointer- Throws:
- IllegalArgumentException- if the buffer is not direct.
 
- 
toStringObtain a Java String from the given native byte array. If there is no NUL terminator, the String will comprise the entire array. The encoding is obtained fromgetDefaultStringEncoding().- Parameters:
- buf- The buffer containing the encoded bytes
- See Also:
 
- 
toStringObtain a Java String from the given native byte array, using the given encoding. If there is no NUL terminator, the String will comprise the entire array.Usage note: This function assumes, that bufholds achararray. This means only single-byte encodings are supported.- Parameters:
- buf- The buffer containing the encoded bytes. Must not be- null.
- encoding- The encoding name - if- nullthen the platform default encoding will be used
 
- 
toStringObtain a Java String from the given native byte array, using the given encoding. If there is no NUL terminator, the String will comprise the entire array.Usage note: This function assumes, that bufholds achararray. This means only single-byte encodings are supported.- Parameters:
- buf- The buffer containing the encoded bytes. Must not be- null.
- charset- The charset to decode- buf. Must not be- null.
 
- 
toStringObtain a Java String from the given native wchar_t array. If there is no NUL terminator, the String will comprise the entire array.- Parameters:
- buf- The buffer containing the characters
 
- 
toStringListConverts a "list" of strings each null terminated into aListofStringvalues. The end of the list is signaled by an extra NULL value at the end or by the end of the buffer.- Parameters:
- buf- The buffer containing the strings
- Returns:
- A Listof all the strings in the buffer
- See Also:
 
- 
toStringListConverts a "list" of strings each null terminated into aListofStringvalues. The end of the list is signaled by an extra NULL value at the end or by the end of the data.- Parameters:
- buf- The buffer containing the strings
- offset- Offset to start parsing
- len- The total characters to parse
- Returns:
- A Listof all the strings in the buffer
 
- 
loadMap a library interface to the current process, providing the explicit interface class. Native libraries loaded via this method may be found in several locations.- Type Parameters:
- T- Type of expected wrapper
- Parameters:
- interfaceClass- The implementation wrapper interface
- Returns:
- an instance of the requested interface, mapped to the current process.
- Throws:
- UnsatisfiedLinkError- if the library cannot be found or dependent libraries are missing.
 
- 
loadMap a library interface to the current process, providing the explicit interface class. Any options provided for the library are cached and associated with the library and any of its defined structures and/or functions. Native libraries loaded via this method may be found in several locations.- Type Parameters:
- T- Type of expected wrapper
- Parameters:
- interfaceClass- The implementation wrapper interface
- options- Map of library options
- Returns:
- an instance of the requested interface, mapped to the current process.
- Throws:
- UnsatisfiedLinkError- if the library cannot be found or dependent libraries are missing.
- See Also:
 
- 
loadMap a library interface to the given shared library, providing the explicit interface class. Ifnameis null, attempts to map onto the current process. Native libraries loaded via this method may be found in several locations.- Type Parameters:
- T- Type of expected wrapper
- Parameters:
- name- Library base name
- interfaceClass- The implementation wrapper interface
- Returns:
- an instance of the requested interface, mapped to the indicated native library.
- Throws:
- UnsatisfiedLinkError- if the library cannot be found or dependent libraries are missing.
- See Also:
 
- 
loadpublic static <T extends Library> T load(String name, Class<T> interfaceClass, Map<String, ?> options) Load a library interface from the given shared library, providing the explicit interface class and a map of options for the library. If no library options are detected the map is interpreted as a map of Java method names to native function names.If nameis null, attempts to map onto the current process. Native libraries loaded via this method may be found in several locations.- Type Parameters:
- T- Type of expected wrapper
- Parameters:
- name- Library base name
- interfaceClass- The implementation wrapper interface
- options- Map of library options
- Returns:
- an instance of the requested interface, mapped to the indicated native library.
- Throws:
- UnsatisfiedLinkError- if the library cannot be found or dependent libraries are missing.
 
- 
loadLibraryDeprecated.Provided for improved compatibility between JNA 4.X and 5.X- See Also:
 
- 
loadLibraryDeprecated.Provided for improved compatibility between JNA 4.X and 5.X- See Also:
 
- 
loadLibraryDeprecated.Provided for improved compatibility between JNA 4.X and 5.X- See Also:
 
- 
loadLibrary@Deprecated public static <T> T loadLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) Deprecated.Provided for improved compatibility between JNA 4.X and 5.X
- 
findEnclosingLibraryClassFind the library interface corresponding to the given class. Checks all ancestor classes and interfaces for a declaring class which implementsLibrary.- Parameters:
- cls- The given class
- Returns:
- The enclosing class
 
- 
getLibraryOptionsReturn the preferred native library configuration options for the given class. First attempts to load any field of the interface type within the interface mapping, then checks the cache for any specified library options. If none found, a set of library options will be generated from the fields (by order of precedence)OPTIONS(aMap),TYPE_MAPPER(aTypeMapper),STRUCTURE_ALIGNMENT(anInteger), andSTRING_ENCODING(aString).- Parameters:
- type- The type class
- Returns:
- The options map
 
- 
getTypeMapperReturn the preferredTypeMapperfor the given native interface. SeeLibrary.OPTION_TYPE_MAPPER.
- 
getStringEncoding- Parameters:
- cls- The native interface type
- Returns:
- The preferred string encoding for the given native interface.
 If there is no setting, defaults to the getDefaultStringEncoding().
- See Also:
 
- 
getDefaultStringEncoding- Returns:
- The default string encoding.  Returns the value of the system
 property jna.encodingorDEFAULT_ENCODING.
 
- 
getStructureAlignment- Parameters:
- cls- The native interface type
- Returns:
- The preferred structure alignment for the given native interface.
- See Also:
 
- 
getBytes- Parameters:
- s- The input string
- Returns:
- A byte array corresponding to the given String.  The encoding
 used is obtained from getDefaultStringEncoding().
 
- 
getBytes- Parameters:
- s- The string. Must not be- null.
- encoding- The encoding - if- nullthen the default platform encoding is used
- Returns:
- A byte array corresponding to the given String, using the given encoding. If the encoding is not found default to the platform native encoding.
 
- 
getBytes- Parameters:
- s- The string. Must not be- null.
- charset- The charset used to encode- s. Must not be- null.
- Returns:
- A byte array corresponding to the given String, using the given charset.
 
- 
toByteArray- Parameters:
- s- The string
- Returns:
- A NUL-terminated byte buffer equivalent to the given String,
 using the encoding returned by getDefaultStringEncoding().
- See Also:
 
- 
toByteArray- Parameters:
- s- The string. Must not be- null.
- encoding- The encoding - if- nullthen the default platform encoding is used
- Returns:
- A NUL-terminated byte buffer equivalent to the given String, using the given encoding.
- See Also:
 
- 
toByteArray- Parameters:
- s- The string. Must not be- null.
- charset- The charset used to encode- s. Must not be- null.
- Returns:
- A NUL-terminated byte buffer equivalent to the given String, using the given charset.
- See Also:
 
- 
toCharArray- Parameters:
- s- The string
- Returns:
- A NUL-terminated wide character buffer equivalent to the given string.
 
- 
isUnpackedIdentify temporary files unpacked from classpath jar files.
- 
extractFromResourcePathAttempt to extract a native library from the current resource path, using the current thread context class loader.- Parameters:
- name- Base name of native library to extract. May also be an absolute resource path (i.e. starts with "/"), in which case the no transformations of the library name are performed. If only the base name is given, the resource path is attempted both with and without- Platform.RESOURCE_PREFIX, after mapping the library name via- NativeLibrary.mapSharedLibraryName(String).
- Returns:
- File indicating extracted resource on disk
- Throws:
- IOException- if resource not found
 
- 
extractFromResourcePathAttempt to extract a native library from the resource path using the given class loader.- Parameters:
- name- Base name of native library to extract. May also be an absolute resource path (i.e. starts with "/"), in which case the no transformations of the library name are performed. If only the base name is given, the resource path is attempted both with and without- Platform.RESOURCE_PREFIX, after mapping the library name via- NativeLibrary.mapSharedLibraryName(String).
- loader- Class loader to use to load resources
- Returns:
- File indicating extracted resource on disk
- Throws:
- IOException- if resource not found
 
- 
getLastErrorpublic static int getLastError()Retrieve last error set by the OS. This corresponds toGetLastError()on Windows, anderrnoon most other platforms. The value is preserved per-thread, but whether the original value is per-thread depends on the underlying OS.An alternative method of obtaining the last error result is to declare your mapped method to throw LastErrorExceptioninstead. If a method's signature includes a throw ofLastErrorException, the last error will be set to zero before the native call and aLastErrorExceptionwill be raised if the last error value is non-zero after the call, regardless of the actual returned value from the native function.
- 
setLastErrorpublic static void setLastError(int code) Set the OS last error code. The value will be saved on a per-thread basis.
- 
synchronizedLibraryReturns a synchronized (thread-safe) library backed by the specified library. This wrapping will prevent simultaneous invocations of any functions mapped to a givenNativeLibrary. Note that the native library may still be sensitive to being called from different threads.- Parameters:
- library- the library to be "wrapped" in a synchronized library.
- Returns:
- a synchronized view of the specified library.
 
- 
getWebStartLibraryPathIf running web start, determine the location of a given native library. This value may be used to properly setjna.library.pathso that JNA can load libraries identified by the <nativelib> tag in the JNLP configuration file. Returnsnullif the Web Start native library cache location can not be determined. Note that the path returned may be different for any given library name.Use System.getProperty("javawebstart.version")to detect whether your code is running under Web Start.- Returns:
- null if unable to query the web start loader.
- Throws:
- UnsatisfiedLinkError- if the library can't be found by the Web Start class loader, which usually means it wasn't included as a- <nativelib>resource in the JNLP file.
 
- 
markTemporaryFilePerform cleanup of automatically unpacked native shared library.
- 
getTempDirObtain a directory suitable for writing JNA-specific temporary files. Override withjna.tmpdir- Throws:
- IOException
 
- 
removeTemporaryFilesRemove all marked temporary files in the given directory.- Throws:
- IOException
 
- 
getNativeSize- Parameters:
- type- The Java class for which the native size is to be determined
- value- an instance of said class (if available)
- Returns:
- the native size of the given class, in bytes. For use with arrays.
 
- 
getNativeSizeReturns the native size for a given Java class. Structures are assumed to bestructpointers unless they implementStructure.ByValue.- Parameters:
- cls- The Java class
- Returns:
- The native size for the class
 
- 
isSupportedNativeType- Parameters:
- cls- The Java class
- Returns:
- truewhether the given class is supported as a native argument type.
 
- 
setCallbackExceptionHandlerSet the default handler invoked when a callback throws an uncaught exception. If the given handler isnull, the default handler will be reinstated.- Parameters:
- eh- The default handler
 
- 
getCallbackExceptionHandler- Returns:
- the current handler for callback uncaught exceptions.
 
- 
registerWhen called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.- Parameters:
- libName- library name to which functions should be bound
 
- 
registerWhen called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.- Parameters:
- lib- native library to which functions should be bound
 
- 
findDirectMappedClassFind the nearest enclosing class with native methods.
- 
getCallingClassTry to determine the class context in which aregister(String)call was made.
- 
setCallbackThreadInitializerSet a thread initializer for the given callback.- Parameters:
- cb- The callback to invoke
- initializer- The thread initializer indicates desired thread configuration when the given Callback is invoked on a native thread not yet attached to the VM.
 
- 
unregisterpublic static void unregister()Remove all native mappings for the calling class. Should only be called if the class is no longer referenced and about to be garbage collected.
- 
unregisterRemove all native mappings for the given class. Should only be called if the class is no longer referenced and about to be garbage collected.
- 
registered- Parameters:
- cls- The type- Class
- Returns:
- whether the given class's native components are registered.
 
- 
getSignature
- 
replace
- 
registerWhen called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface. Uses the class loader of the given class to search for the native library in the resource path if it is not found in the system library load path orjna.library.path.- Parameters:
- cls- Class with native methods to register
- libName- name of or path to native library to which functions should be bound
 
- 
registerWhen called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.- Parameters:
- cls- Class with native methods to register
- lib- library to which functions should be bound
 
- 
ffi_prep_cifpublic static long ffi_prep_cif(int abi, int nargs, long ffi_return_type, long ffi_types) Create a new cif structure.
- 
ffi_callpublic static void ffi_call(long cif, long fptr, long resp, long args) Make an FFI function call.
- 
ffi_prep_closure
- 
ffi_free_closurepublic static void ffi_free_closure(long closure) 
- 
initialize_ffi_typestatic int initialize_ffi_type(long type_info) Returns the size (calculated by libffi) of the given type.
- 
mainPrints JNA library details to the console.
- 
freeNativeCallbackstatic void freeNativeCallback(long ptr) Free the given callback trampoline.
- 
createNativeCallbackstatic long createNativeCallback(Callback callback, Method method, Class<?>[] parameterTypes, Class<?> returnType, int callingConvention, int flags, String encoding) Create a native trampoline to delegate execution to the Java callback.
- 
invokeIntCall the native function.- Parameters:
- function- Present to prevent the GC to collect the Function object prematurely
- fp- function pointer
- callFlags- calling convention to be used
- args- Arguments to pass to the native function
- Returns:
- The value returned by the target native function
 
- 
invokeLongCall the native function.- Parameters:
- function- Present to prevent the GC to collect the Function object prematurely
- fp- function pointer
- callFlags- calling convention to be used
- args- Arguments to pass to the native function
- Returns:
- The value returned by the target native function
 
- 
invokeVoidCall the native function.- Parameters:
- function- Present to prevent the GC to collect the Function object prematurely
- fp- function pointer
- callFlags- calling convention to be used
- args- Arguments to pass to the native function
 
- 
invokeFloatCall the native function.- Parameters:
- function- Present to prevent the GC to collect the Function object prematurely
- fp- function pointer
- callFlags- calling convention to be used
- args- Arguments to pass to the native function
- Returns:
- The value returned by the target native function
 
- 
invokeDoubleCall the native function.- Parameters:
- function- Present to prevent the GC to collect the Function object prematurely
- fp- function pointer
- callFlags- calling convention to be used
- args- Arguments to pass to the native function
- Returns:
- The value returned by the target native function
 
- 
invokePointerCall the native function.- Parameters:
- function- Present to prevent the GC to collect the Function object prematurely
- fp- function pointer
- callFlags- calling convention to be used
- args- Arguments to pass to the native function
- Returns:
- The value returned by the target native function
 
- 
invokeStructurestatic Structure invokeStructure(Function function, long fp, int callFlags, Object[] args, Structure s) Call the native function, returning a struct by value.- Parameters:
- function- Present to prevent the GC to collect the Function object prematurely
- fp- function pointer
- callFlags- calling convention to be used
- args- Arguments to pass to the native function
- Returns:
- the passed-in Structure
 
- 
invokeObjectCall the native function, returning a JavaObject.- Parameters:
- function- Present to prevent the GC to collect the Function object prematurely
- fp- function pointer
- callFlags- calling convention to be used
- args- Arguments to pass to the native function
- Returns:
- The returned Java Object
 
- 
openOpen the requested native library with default options.
- 
openOpen the requested native library with the specified platform-specific otions.
- 
closestatic void close(long handle) Close the given native library.
- 
findSymbol
- 
indexOf
- 
read
- 
read
- 
read
- 
read
- 
read
- 
read
- 
read
- 
write
- 
write
- 
write
- 
write
- 
write
- 
write
- 
write
- 
getByte
- 
getChar
- 
getShort
- 
getInt
- 
getLong
- 
getFloat
- 
getDouble
- 
getPointer
- 
getWideString
- 
getString
- 
getString
- 
getStringBytes
- 
setMemory
- 
setByte
- 
setShort
- 
setChar
- 
setInt
- 
setLong
- 
setFloat
- 
setDouble
- 
setPointer
- 
setWideString
- 
getDirectByteBuffer
- 
mallocpublic static long malloc(long size) Call the real native malloc- Parameters:
- size- size of the memory to be allocated
- Returns:
- native address of the allocated memory block; zero if the allocation failed.
 
- 
freepublic static void free(long ptr) Call the real native free- Parameters:
- ptr- native address to be freed; a value of zero has no effect, passing an already-freed pointer will cause pain.
 
- 
detachpublic static void detach(boolean detach) Indicate whether the JVM should detach the current native thread when the current Java code finishes execution. Generally this is used to avoid detaching native threads when it is known that a given thread will be relatively long-lived and call back to Java code frequently. This call is lightweight; it only results in an additional JNI crossing if the desired state changes from its last setting.- Throws:
- IllegalStateException- if- detach(true)is called on a thread created by the JVM.
 
- 
getTerminationFlag
 
-