Error Running jextract on d3d12.h
Ty Young
youngty1997 at gmail.com
Sat Sep 12 08:40:58 UTC 2020
Not a JDK developer, but if you want to do this by hand(aka no
jextract), I had to do this for NVAPI which obfuscates function pointers
using keys, e.g.:
nvapi_h.nvapi_QueryInterface(0x0150e828);
where "0x0150e828" is the "NvAPI_Initialize" function key as per the
Open Source headers Nvidia released sometime ago.
The only difference is that, since the function pointer is in a struct,
you need to get the segment in the struct containing the function
pointer(see "slice" MemorySegment method) and actually read from it
using a VarHandle. You then take that MemoryAddress, with a
FunctionDescriptor and MethodType, and create a MethodHandle. For
reference, this my working code("NativeFunction" and "NativeTypes" do
not exist in Panama, those are mine but they dont matter) for the
NvAPI_Initalize API:
public class NvAPI_Initialize implements NativeFunction
{
private final MemoryAddress address;
private final FunctionDescriptor descriptor;
private final MethodType type;
private final MethodHandle handle;
public NvAPI_Initialize() throws NoSuchMethodException, Throwable
{
this.address = nvapi_h.nvapi_QueryInterface(0x0150e828);
this.descriptor = FunctionDescriptor.of(NativeTypes.INT);
this.type = MethodType.methodType(int.class);
this.handle =
CSupport.getSystemLinker().downcallHandle(this.address, this.type,
this.descriptor);
}
// etc
}
It looks like in your case the FunctionDescriptor would be:
this.descriptor = FunctionDescriptor.of(CSupport.C_POINTER,
CSupport.C_INT, CSupport.C_POINTER);
for MethodType:
MethodType.methodType(MemoryAddress.class, int.class, MemoryAddress.class);
where the first argument takes in a IDXGIFactory, the second an unsigned
int, and the third a pointer to what looks like an opaque device that
you pass to other functions.
If you haven't already, it might help to make bindings with a smaller,
less complicated library just to get a feel with how things work under
the hood.
Hope this helps.
On 9/12/20 2:23 AM, Michael Ennen wrote:
> Looking into this a bit further I think I chose a really bad library to
> start with as the function I need to call, EnumAdapters, is inside
> some type of "VTbl" struct that is trying to emulate a C++ class with
> virtual functions. What jextract is returning is most likely *correct*
> but in this case so complicated because of how it is laid out in C. It is
> not clear at all how to grab the EnumAdapters function from
> this mess, and it is probably above my head.
>
> EXTERN_C const IID IID_IDXGIFactory;
>
> #if defined(__cplusplus) && !defined(CINTERFACE)
>
> MIDL_INTERFACE("7b7166ec-21c7-44ae-b21a-c9ae321ae369")
> IDXGIFactory : public IDXGIObject
> {
> public:
> virtual HRESULT STDMETHODCALLTYPE EnumAdapters(
> /* [in] */ UINT Adapter,
> /* [annotation][out] */
> _COM_Outptr_ IDXGIAdapter **ppAdapter) = 0;
>
> virtual HRESULT STDMETHODCALLTYPE MakeWindowAssociation(
> HWND WindowHandle,
> UINT Flags) = 0;
>
> virtual HRESULT STDMETHODCALLTYPE GetWindowAssociation(
> /* [annotation][out] */
> _Out_ HWND *pWindowHandle) = 0;
>
> virtual HRESULT STDMETHODCALLTYPE CreateSwapChain(
> /* [annotation][in] */
> _In_ IUnknown *pDevice,
> /* [annotation][in] */
> _In_ DXGI_SWAP_CHAIN_DESC *pDesc,
> /* [annotation][out] */
> _COM_Outptr_ IDXGISwapChain **ppSwapChain) = 0;
>
> virtual HRESULT STDMETHODCALLTYPE CreateSoftwareAdapter(
> /* [in] */ HMODULE Module,
> /* [annotation][out] */
> _COM_Outptr_ IDXGIAdapter **ppAdapter) = 0;
>
> };
>
>
> #else /* C style interface */
>
> typedef struct IDXGIFactoryVtbl
> {
> BEGIN_INTERFACE
>
> HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
> IDXGIFactory * This,
> /* [in] */ REFIID riid,
> /* [annotation][iid_is][out] */
> _COM_Outptr_ void **ppvObject);
>
> ULONG ( STDMETHODCALLTYPE *AddRef )(
> IDXGIFactory * This);
>
> ULONG ( STDMETHODCALLTYPE *Release )(
> IDXGIFactory * This);
>
> HRESULT ( STDMETHODCALLTYPE *SetPrivateData )(
> IDXGIFactory * This,
> /* [annotation][in] */
> _In_ REFGUID Name,
> /* [in] */ UINT DataSize,
> /* [annotation][in] */
> _In_reads_bytes_(DataSize) const void *pData);
>
> HRESULT ( STDMETHODCALLTYPE *SetPrivateDataInterface )(
> IDXGIFactory * This,
> /* [annotation][in] */
> _In_ REFGUID Name,
> /* [annotation][in] */
> _In_opt_ const IUnknown *pUnknown);
>
> HRESULT ( STDMETHODCALLTYPE *GetPrivateData )(
> IDXGIFactory * This,
> /* [annotation][in] */
> _In_ REFGUID Name,
> /* [annotation][out][in] */
> _Inout_ UINT *pDataSize,
> /* [annotation][out] */
> _Out_writes_bytes_(*pDataSize) void *pData);
>
> HRESULT ( STDMETHODCALLTYPE *GetParent )(
> IDXGIFactory * This,
> /* [annotation][in] */
> _In_ REFIID riid,
> /* [annotation][retval][out] */
> _COM_Outptr_ void **ppParent);
>
> HRESULT ( STDMETHODCALLTYPE *EnumAdapters )(
> IDXGIFactory * This,
> /* [in] */ UINT Adapter,
> /* [annotation][out] */
> _COM_Outptr_ IDXGIAdapter **ppAdapter);
>
> HRESULT ( STDMETHODCALLTYPE *MakeWindowAssociation )(
> IDXGIFactory * This,
> HWND WindowHandle,
> UINT Flags);
>
> HRESULT ( STDMETHODCALLTYPE *GetWindowAssociation )(
> IDXGIFactory * This,
> /* [annotation][out] */
> _Out_ HWND *pWindowHandle);
>
> HRESULT ( STDMETHODCALLTYPE *CreateSwapChain )(
> IDXGIFactory * This,
> /* [annotation][in] */
> _In_ IUnknown *pDevice,
> /* [annotation][in] */
> _In_ DXGI_SWAP_CHAIN_DESC *pDesc,
> /* [annotation][out] */
> _COM_Outptr_ IDXGISwapChain **ppSwapChain);
>
> HRESULT ( STDMETHODCALLTYPE *CreateSoftwareAdapter )(
> IDXGIFactory * This,
> /* [in] */ HMODULE Module,
> /* [annotation][out] */
> _COM_Outptr_ IDXGIAdapter **ppAdapter);
>
> END_INTERFACE
> } IDXGIFactoryVtbl;
>
> interface IDXGIFactory
> {
> CONST_VTBL struct IDXGIFactoryVtbl *lpVtbl;
> };
>
>
More information about the panama-dev
mailing list