Class FunctionPointer

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public abstract class FunctionPointer
    extends Pointer
    All peer classes to function pointers must derive from FunctionPointer. Defining a subclass lets Generator create a native function type. A C++ function object gets instantiated for each call to allocate() as well. That function object can be accessed by annotating any method parameter with ByVal or ByRef. By default, an actual function pointer gets passed ByPtr.

    To use FunctionPointer, subclass and add a native method named call() or apply(), along with its return type and parameters, as well as the usual native void allocate() method to support explicit allocation, which is typically a requirement for callback functions. We can implement a callback in Java by further subclassing and overriding call/apply().

    If you have an address to a native function, it is also possible to call it by defining a ValueSetter method with a single Pointer parameter, along with native declarations for allocate() and call(). After allocating the object and setting the value, we can be call it from Java.

    See Also:
    Generator
    • Constructor Detail

      • FunctionPointer

        protected FunctionPointer()
      • FunctionPointer

        protected FunctionPointer​(Pointer p)