Windows DXGI Experiment

Hugo De Vaan hdevaan76 at gmail.com
Tue Feb 25 17:05:10 UTC 2025


Thank you, I was mistaken about the layout, so changing the UUID indeed
makes the factory creation succeed.

The buffer is a leftover from earlier work in the same class, where I tried
a more specific DirectX 12 approach (CreateDXGIFactory2 and such). Since
the September 2020 example in this mailing list is the best fitting example
I could find, I turned the experiment into an earlier DirectX version. I
kept some of the other code, which turns out to be a mistake, because I
mislead myself into trying to find the error in the wrong place.

Anyway, since that post I have made some progress, trying to call a virtual
function as per C instead of C++. Thankfully, Microsoft COM objects follow
a standard of "pointing to interface -> pointing to vtable" on the offsets,
so I expected to just follow several pointers in succession and be able to
get to the functions of the IDXGIFactory.

However, with the addition of Jorn's recommendation, I will change my
approach. If there is no need to manually 'mess around' with vtable
mapping, I'd rather have jextract do it for me.

PS: I believe the 2025 way of dereferencing looks _roughly_ like this
(because I might well be wrong about the getters, perhaps it should have
been x.address()):

MemorySegment vtable = factory.get(ValueLayout.ADDRESS, 0).reinterpret(8,
Arena.global(), null);
MemorySegment fpointer = vtable.get(ValueLayout.ADDRESS, 0).reinterpret(8,
Arena.global(), null);

FunctionDescriptor fdesc = FunctionDescriptor.of(
    ValueLayout.JAVA_INT, // return value
    ValueLayout.ADDRESS,  // vtable reference - not sure if I need this
    ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS //
parameters);

MethodHandle handle = linker.downcallHandle(fpointer, fdesc);
System.out.println("Handle to QueryInterface created.");

hresult = (int) handle.invokeExact(vtable, factory, uuidValue, factory);

Anyway, thanks again for the help, it has allowed me to continue my FFM
experiments.

Kind regards,
Hugo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20250225/1a7eb534/attachment.htm>


More information about the panama-dev mailing list