To embed a callback inside a structure, you can first call the com.ms.dll.Root.alloc method to wrap the callback in a root handle. Then pass the root handle to the DllLib.addrOf method to obtain the actual (native) address of the callback. Then, store this address as an integer.
For example, the WNDCLASS structure can be declared in Java as:
/** @dll.struct() */
class WNDCLASS {
int style;
int lpfnWndProc; // CALLBACK
... /* <other fields deleted for brevity> */
}
Let's assume you have extended Callback as follows:
class WNDPROC extends Callback
{
public int callback(int hwnd, int msg, int wparam, int lparam)
{
...
}
}
To store a pointer to the callback inside the WNDCLASS object, use the following sequence:
import com.ms.dll.*;
WNDCLASS wc = new WNDCLASS();
int callbackroot = Root.alloc(new WNDPROC());
wc.lpfnWndProc = DllLib.addrOf(callbackroot);