来自指针的Java JNA类方法
我试图从Direct2D类ID2DFactory中映射一个函数,我设法使用该类进行移植 现在我想到的下一步是使用来自指针的Java JNA类方法,java,directx,jna,Java,Directx,Jna,我试图从Direct2D类ID2DFactory中映射一个函数,我设法使用该类进行移植 现在我想到的下一步是使用Function.getFunction(获取函数,然后使用Function.invokeXXX()获得一个工作方法 现在这似乎比我想象的要难。下面的代码就是我试图实现的目标 D2D1_FACTORY_OPTIONS opts = new D2D1_FACTORY_OPTIONS(); PointerByReference pp = new PointerByRefer
Function.getFunction(
获取函数,然后使用Function.invokeXXX()
获得一个工作方法
现在这似乎比我想象的要难。下面的代码就是我试图实现的目标
D2D1_FACTORY_OPTIONS opts = new D2D1_FACTORY_OPTIONS();
PointerByReference pp = new PointerByReference();
HRESULT hres = D2D1.INSTANCE.D2D1CreateFactory(0, new REFIID(new IID("06152247-6F50-465A-9245-118BFD3B6007").toByteArray()), opts, pp);
//hres returns 0 which means it was successful.
// I thought that, since pp is a reference to a reference to the Factory,
// that getValue().getPointer(0) would give me the Factory, and thus the
// first Pointer 'ReloadSystemMetrics()'.
Function fnc = Function.getFunction(pp.getValue().getPointer(0).getPointer(0), Function.ALT_CONVENTION);
fnc.invokeInt(null); // I have aswell tried new Object[] {}. This does not throw an error.
//This is (or should be) GetDesktopDpi(Float*, Float*).
Function fncGetdpi = Function.getFunction(pp.getValue().getPointer(0).getPointer(1), Function.ALT_CONVENTION);
FloatByReference x, y;
x = y = new FloatByReference();
fncGetdpi.invokeVoid(new Object[] {x, y}); //But this gives 'Invalid memory access'
我还没有实现我想要的目标。希望有人能告诉我我做错了什么:)嗨,巴特。你最终做对了吗?我知道已经三个月了?很遗憾我没能做到。我经常检查,但运气不好。