Top Description Inners Fields Constructors Methods
com.sun.jna

public Class Function

extends Pointer
Class Inheritance
Imports
java.lang.reflect.InvocationTargetException, .Method, java.util.Collections, .HashMap, .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.
Authors
Sheng Liang, originator, Todd Fast, suitability modifications
See Also
Pointer

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

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.

private int
private String
private NativeLibrary
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.

Inherited from com.sun.jna.Pointer:
NULLpeerSIZE

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
Calling convention used by the native function
callingConvention
)

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
Calling convention used by the native function
callingConvention
)

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)

public boolean
equals(Object
A Pointer instance
o
)

Overrides com.sun.jna.Pointer.equals.

Two function pointers are equal if they share the same peer address and calling convention.
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
Call convention used by the native function
callConvention
)

Obtain a Function representing a native function that follows a given calling convention.

public String
public Object
invoke(Class<T> returnType, Object[] inArgs)

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

public Object
invoke(Class<T> returnType, Object[] inArgs, Map<K, V> options)

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

pack-priv Object
invoke(Object[] args, Class<T> returnType)

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

Call the native function being represented by this object

private native double

Returns:

The value returned by the target native function
invokeDouble
(int
calling convention to be used
callingConvention
,
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).

private native float

Returns:

The value returned by the target native function
invokeFloat
(int
calling convention to be used
callingConvention
,
Object[]
Arguments to pass to the native function
args
)

Call the native function being represented by this object

public float
invokeFloat(Object[] args)

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

private native int

Returns:

The value returned by the target native function
invokeInt
(int
calling convention to be used
callingConvention
,
Object[]
Arguments to pass to the native function
args
)

Call the native function being represented by this object

public int
invokeInt(Object[] args)

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

private native long

Returns:

The value returned by the target native function
invokeLong
(int
calling convention to be used
callingConvention
,
Object[]
Arguments to pass to the native function
args
)

Call the native function being represented by this object

public long
invokeLong(Object[] args)

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

private native Pointer

Returns:

The native pointer returned by the target native function
invokePointer
(int
calling convention to be used
callingConvention
,
Object[]
Arguments to pass to the native function
args
)

Call the native function being represented by this object

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
callingConvention
,
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)

private native Structure

Returns:

The native pointer returned by the target native function
invokeStructure
(int
calling convention to be used
callingConvention
,
Object[]
Arguments to pass to the native function
args
,
Structure
Pre-allocated structure to hold the result
result
)

Call the native function being represented by this object

private native void
invokeVoid(int
calling convention to be used
callingConvention
,
Object[]
Arguments to pass to the native function
args
)

Call the native function being represented by this object

public void
invokeVoid(Object[] args)

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

private boolean
isPrimitiveArray(Class<T> 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.
Inherited from com.sun.jna.Pointer:
clearcreateConstantgetBytegetByteArraygetByteBuffergetChargetCharArraygetDoublegetDoubleArraygetFloatgetFloatArraygetIntgetIntArraygetLonggetLongArraygetNativeLonggetPointergetPointerArraygetShortgetShortArraygetStringgetStringhashCodeindexOfreadreadreadreadreadreadreadreadsetBytesetCharsetDoublesetFloatsetIntsetLongsetMemorysetNativeLongsetPointersetShortsetStringsetStringsharesharewritewritewritewritewritewritewritewrite

Field Detail

ALT_CONVENTIONback to summary
public static final int ALT_CONVENTION

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

C_CONVENTIONback to summary
public static final int C_CONVENTION

Standard C calling convention.

callingConventionback to summary
private int callingConvention
functionNameback to summary
private String functionName
libraryback to summary
private NativeLibrary library
MAX_NARGSback to summary
public static final int MAX_NARGS

Maximum number of arguments supported by a JNA function call.

OPTION_INVOKING_METHODback to summary
pack-priv static final String OPTION_INVOKING_METHOD

For internal JNA use.

Constructor Detail

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

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

callingConvention:int

Calling convention used by the native function

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

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

callingConvention:int

Calling convention used by the native function

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)
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 com.sun.jna.Pointer.equals.

A Pointer instance

Returns:boolean

Doc from com.sun.jna.Pointer.equals.

True if the other object is a Pointer, and the C pointers being pointed to by these objects are also equal. Returns false otherwise.

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 callConvention)

Obtain a Function representing a native function that follows a given calling convention.

The allocated instance represents a pointer to the named native function from the named library, called with the named calling convention.

Parameters
libraryName:String

Library in which to find the function

functionName:String

Name of the native function to be linked with

callConvention:int

Call convention used by the native function

Exceptions
UnsatisfiedLinkError:
if the library is not found or the given function name is not found within the library.
getNameback to summary
public String getName()
invokeback to summary
public Object invoke(Class<T> 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<T> returnType, Object[] inArgs, Map<K, V> options)

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

invokeback to summary
pack-priv Object invoke(Object[] args, Class<T> returnType)
See Also
implementation
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
private native double invokeDouble(int callingConvention, Object[] args)

Call the native function being represented by this object

Parameters
callingConvention:int

calling convention to be used

args:Object[]

Arguments to pass to the native function

Returns:double

The value returned by the target native function

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

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

invokeFloatback to summary
private native float invokeFloat(int callingConvention, Object[] args)

Call the native function being represented by this object

Parameters
callingConvention:int

calling convention to be used

args:Object[]

Arguments to pass to the native function

Returns:float

The value returned by the target native function

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

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

invokeIntback to summary
private native int invokeInt(int callingConvention, Object[] args)

Call the native function being represented by this object

Parameters
callingConvention:int

calling convention to be used

args:Object[]

Arguments to pass to the native function

Returns:int

The value returned by the target native function

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

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

invokeLongback to summary
private native long invokeLong(int callingConvention, Object[] args)

Call the native function being represented by this object

Parameters
callingConvention:int

calling convention to be used

args:Object[]

Arguments to pass to the native function

Returns:long

The value returned by the target native function

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

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

invokePointerback to summary
private native Pointer invokePointer(int callingConvention, Object[] args)

Call the native function being represented by this object

Parameters
callingConvention:int

calling convention to be used

args:Object[]

Arguments to pass to the native function

Returns:Pointer

The native pointer returned by the target native function

invokePointerback to summary
public Pointer invokePointer(Object[] args)

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

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

Call the native function being represented by this object

Parameters
callingConvention: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*.

invokeStructureback to summary
private native Structure invokeStructure(int callingConvention, Object[] args, Structure result)

Call the native function being represented by this object

Parameters
callingConvention:int

calling convention to be used

args:Object[]

Arguments to pass to the native function

result:Structure

Pre-allocated structure to hold the result

Returns:Structure

The native pointer returned by the target native function

invokeVoidback to summary
private native void invokeVoid(int callingConvention, Object[] args)

Call the native function being represented by this object

Parameters
callingConvention:int

calling convention to be used

args:Object[]

Arguments to pass to the native function

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

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

isPrimitiveArrayback to summary
private boolean isPrimitiveArray(Class<T> 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.

com.sun.jna back to summary

private Class Function.PointerArray

extends Memory
Class Inheritance

Field Summary

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

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
read()

Inherited from com.sun.jna.Memory:
alignboundsCheckclearfinalizefreegetBytegetByteBuffergetChargetDoublegetFloatgetIntgetLonggetPointergetShortgetSizegetStringisValidmallocreadreadreadreadreadreadreadsetBytesetCharsetDoublesetFloatsetIntsetLongsetPointersetShortsetStringsharesharetoStringwritewritewritewritewritewritewrite

Field Detail

originalback to summary
private Pointer[] original

Constructor Detail

PointerArrayback to summary
public PointerArray(Pointer[] arg)

Method Detail

readback to summary
public void read()