来自指针的Java JNA类方法

时间:2013-03-25 20:36:08

标签: java directx jna

我试图从Direct2D类ID2DFactory中获取映射的函数,我设法使用this previous question进行移植。

现在我想到的下一步是使用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'

我在实现我想要的东西方面没有运气。希望有人可以让我了解我做错了什么:)

0 个答案:

没有答案