I already know how to wrap an Structure , but I need some help with interfaces. The interface I want to wrap is the IImageList.
But I have now clue how to create an java class out of it.
I already know how to wrap an Structure , but I need some help with interfaces. The interface I want to wrap is the IImageList.
But I have now clue how to create an java class out of it.
This can be done, but you will need access to the header file. The IImageList documentation tells you this comes from commoncontrols.h. Refer to this source file for the following discussion.
Although not mandatory, for organization you will want to create a Java class for the header file, e.g., CommonControls.java
. Inside that create a class for the interface, extending JNA's Unknown
class and add the method(s) you want. The methods should use _invokeNativeObject()
(or the void
or int
variants). The key point here is that you'll need the vtableId
. This is where you go back to the header file listed earlier. Find the IImageListVtbl
entry in the header (it's on line 322) and count the methods (0-indexed) to find which ID corresponds to the method you want. vtableID = 0 would be QueryInterface
. Id 1 is AddRef
. And so on.
See, as an example, how I implemented several interfaces from wbemcli.h in this Wbemcli.java class. One example implements the IEnumWbemClassObject::Next
method thus:
class IEnumWbemClassObject extends Unknown {
public IEnumWbemClassObject(Pointer pvInstance) {
super(pvInstance);
}
public HRESULT Next(int lTimeOut, int uCount, PointerByReference ppObjects, IntByReference puReturned) {
// Next is 5th method of IEnumWbemClassObjectVtbl in
// WbemCli.h
return (HRESULT) _invokeNativeObject(4,
new Object[] { getPointer(), lTimeOut, uCount, ppObjects, puReturned }, HRESULT.class);
}
}
You can add multiple methods (or all of them) in the same class.
This ended up being the solution:
class IImageList extends Unknown {
public IImageList(Pointer pvInstance) {
super(pvInstance);
}
public WinNT.HRESULT GetIcon(int i, int flags, PointerByReference picon) {
return (WinNT.HRESULT) _invokeNativeObject(10,
new Object[]{this.getPointer(), i, flags, picon},WinNT.HRESULT.class);
}
}