/** * Obtain a <code>Function</code> 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. * * <p>The allocated instance represents a pointer to the native * function pointer. * * @param p * Native function pointer * @param callFlags * Function <a href="#callflags">call flags</a> * @param encoding * Encoding to use for conversion between Java and native * strings. */ public static Function getFunction(Pointer p, int callFlags, String encoding) { return new Function(p, callFlags, encoding); }
public NativeFunctionHandler(Pointer address, int callingConvention, Map<String, ?> options) { this.options = options; this.function = new Function(address, callingConvention, (String) options.get(Library.OPTION_STRING_ENCODING)); }
/** * Create a new {@link Function} that is linked with a native * function that follows a given calling flags. * * @param functionName * Name of the native function to be linked with * @param callFlags * Flags affecting the function invocation * @param encoding * Encoding to use to convert between Java and native * strings. * @throws UnsatisfiedLinkError if the function is not found */ public Function getFunction(String functionName, int callFlags, String encoding) { if (functionName == null) { throw new NullPointerException("Function name may not be null"); } synchronized (functions) { String key = functionKey(functionName, callFlags, encoding); Function function = functions.get(key); if (function == null) { function = new Function(this, functionName, callFlags, encoding); functions.put(key, function); } return function; } }
private NativeLibrary(String libraryName, String libraryPath, long handle, Map<String, ?> options) { this.libraryName = getLibraryName(libraryName); this.libraryPath = libraryPath; this.handle = handle; Object option = options.get(Library.OPTION_CALLING_CONVENTION); int callingConvention = option instanceof Number ? ((Number)option).intValue() : Function.C_CONVENTION; this.callFlags = callingConvention; this.options = options; this.encoding = (String)options.get(Library.OPTION_STRING_ENCODING); if (this.encoding == null) { this.encoding = Native.getDefaultStringEncoding(); } // Special workaround for w32 kernel32.GetLastError // Short-circuit the function to use built-in GetLastError access if (Platform.isWindows() && "kernel32".equals(this.libraryName.toLowerCase())) { synchronized(functions) { Function f = new Function(this, "GetLastError", Function.ALT_CONVENTION, encoding) { @Override Object invoke(Object[] args, Class<?> returnType, boolean b, int fixedArgs) { return Integer.valueOf(Native.getLastError()); } @Override Object invoke(Method invokingMethod, Class<?>[] paramTypes, Class<?> returnType, Object[] inArgs, Map<String, ?> options) { return Integer.valueOf(Native.getLastError()); } }; functions.put(functionKey("GetLastError", callFlags, encoding), f); } } }
/** * Obtain a <code>Function</code> 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. * * <p>The allocated instance represents a pointer to the native * function pointer. * * @param p * Native function pointer * @param callFlags * Function <a href="#callflags">call flags</a> * @param encoding * Encoding to use for conversion between Java and native * strings. */ public static Function getFunction(Pointer p, int callFlags, String encoding) { return new Function(p, callFlags, encoding); }
public NativeFunctionHandler(Pointer address, int callingConvention, Map<String, ?> options) { this.options = options; this.function = new Function(address, callingConvention, (String) options.get(Library.OPTION_STRING_ENCODING)); }
private NativeLibrary(String libraryName, String libraryPath, long handle) { this.libraryName = getLibraryName(libraryName); this.libraryPath = libraryPath; this.handle = handle; // Special workaround for w32 kernel32.GetLastError // Short-circuit the function to use built-in GetLastError access if (Platform.isWindows() && "kernel32".equals(this.libraryName.toLowerCase())) { synchronized(functions) { Function f = new Function(this, "GetLastError", Function.ALT_CONVENTION) { Object invoke(Object[] args, Class returnType) { return new Integer(Native.getLastError()); } }; functions.put("GetLastError", f); } } }
/** * Create a new {@link Function} that is linked with a native * function that follows a given calling flags. * * @param functionName * Name of the native function to be linked with * @param callFlags * Flags affecting the function invocation * @param encoding * Encoding to use to convert between Java and native * strings. * @throws UnsatisfiedLinkError if the function is not found */ public Function getFunction(String functionName, int callFlags, String encoding) { if (functionName == null) { throw new NullPointerException("Function name may not be null"); } synchronized (functions) { String key = functionKey(functionName, callFlags, encoding); Function function = functions.get(key); if (function == null) { function = new Function(this, functionName, callFlags, encoding); functions.put(key, function); } return function; } }
private NativeLibrary(String libraryName, String libraryPath, long handle, Map<String, ?> options) { this.libraryName = getLibraryName(libraryName); this.libraryPath = libraryPath; this.handle = handle; Object option = options.get(Library.OPTION_CALLING_CONVENTION); int callingConvention = option instanceof Number ? ((Number)option).intValue() : Function.C_CONVENTION; this.callFlags = callingConvention; this.options = options; this.encoding = (String)options.get(Library.OPTION_STRING_ENCODING); if (this.encoding == null) { this.encoding = Native.getDefaultStringEncoding(); } // Special workaround for w32 kernel32.GetLastError // Short-circuit the function to use built-in GetLastError access if (Platform.isWindows() && "kernel32".equals(this.libraryName.toLowerCase())) { synchronized(functions) { Function f = new Function(this, "GetLastError", Function.ALT_CONVENTION, encoding) { @Override Object invoke(Object[] args, Class<?> returnType, boolean b, int fixedArgs) { return Integer.valueOf(Native.getLastError()); } @Override Object invoke(Method invokingMethod, Class<?>[] paramTypes, Class<?> returnType, Object[] inArgs, Map<String, ?> options) { return Integer.valueOf(Native.getLastError()); } }; functions.put(functionKey("GetLastError", callFlags, encoding), f); } } }
Function function = (Function) functions.get(functionName); if (function == null) { function = new Function(this, functionName, callingConvention); functions.put(functionName, function);