3

我试图从 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'

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

4

0 回答 0