<div dir="ltr">Greetings fellow developers,<br><br>I've been trying to create a Java layer atop Microsoft's DXGI library in an attempt to get Java to work with Desktop Duplication. Unfortunately, I can't seem to create a DXGI factory. I can locate the symbol just fine, and I've double checked the UUID value for the type (using an earlier message in this mailing list, dating back to September 2020). When invoking the method handle, I get the 0x80004002 HRESULT, which translates to "No such interface supported". I'm not sure what I'm doing wrong here, so I would appreciate any help.<br><br>[code]<br>import java.lang.foreign.Arena;<br>import java.lang.foreign.FunctionDescriptor;<br>import java.lang.foreign.Linker;<br>import java.lang.foreign.MemorySegment;<br>import java.lang.foreign.SymbolLookup;<br>import java.lang.foreign.ValueLayout;<br>import java.lang.invoke.MethodHandle;<br>import java.nio.ByteBuffer;<br>import java.nio.ByteOrder;<br>import java.util.HexFormat;<br><br>public final class DXGIExperiment {<br>    public static final void main(String[] args) {<br>        try {<br>            System.load("C:\\Windows\\System32\\dxgi.dll");<br>                <br>            Linker linker = Linker.nativeLinker();<br>                    <br>              SymbolLookup symbols = SymbolLookup.libraryLookup(<br>                  "C:\\Windows\\System32\\dxgi.dll", Arena.global());<br>                  <br>              /* MemoryLayout BIT128 = MemoryLayout.<br>                      sequenceLayout(16, ValueLayout.JAVA_BYTE); */<br>                        <br>              /* Giving the 128bit UUID directly to the function doesn't <br>               * work - the layout is not supported:<br>               * <br>               * FunctionDescriptor descriptor = FunctionDescriptor.of(<br>               *        ValueLayout.JAVA_INT, BIT128, ValueLayout.ADDRESS);<br>               */<br>                    <br>              FunctionDescriptor descriptor = FunctionDescriptor.of(<br>              ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS);<br>                        <br>              MemorySegment createFactory = <br>                  symbols.find("CreateDXGIFactory1").get();<br>                        <br>             MethodHandle handle = linker.<br>                  downcallHandle(createFactory, descriptor);<br>                    <br>             System.out.println("Handle to CreateDXGIFactory1 created.");<br>                  <br>              byte[] uuidArray = new byte[16];<br>              ByteBuffer buffer = ByteBuffer.wrap(uuidArray);<br>              buffer.order(ByteOrder.LITTLE_ENDIAN);<br>                 <br>              buffer.<br>                  putInt(0x770aae78).<br>                  putInt(0xf26f4dba).<br>                  putInt(0xa829253c).<br>                  putInt(0x83d1b387);<br>                       <br>              MemorySegment factoryPointer = <br>                  Arena.global().allocate(ValueLayout.ADDRESS);<br>                     <br>              MemorySegment uuidValue = <br>                  Arena.global().allocate(16);<br>                   <br>              uuidValue.setAtIndex(ValueLayout.JAVA_INT, 0, buffer.getInt(0));<br>              uuidValue.setAtIndex(ValueLayout.JAVA_INT, 1, buffer.getInt(4));<br>              uuidValue.setAtIndex(ValueLayout.JAVA_INT, 2, buffer.getInt(8));<br>              uuidValue.setAtIndex(ValueLayout.JAVA_INT, 3, buffer.getInt(12));<br>                     <br>              int hresult = (int) handle.<br>                  invokeExact(uuidValue, factoryPointer);<br>                       <br>              System.out.println(<br>                  "Invocation result: " + <br>                  HexFormat.of().toHexDigits(hresult));<br>              } catch (Throwable t) {<br>                  t.printStackTrace();<br>              }<br>      }<br>}<br>[/code]<br><br>PS: This was tried on Windows 10 Pro, 64 bit, build 19045 and running GraalVM 21+35.1<br><div><br></div><div>Regards,</div><div>Hugo</div></div>