Search code examples
c++direct3d

How to use IDirect3D9 functions


I am trying to use the function GetAdapterIdentifier but for some reason I keep on getting an error

g++ main.cpp -ld3d9 -ld3dcompiler -lgdi32 -static -static-libstdc++ -o output
main.cpp: In function 'int main()':
main.cpp:22:59: error: cannot call member function 'virtual HRESULT IDirect3D9::GetAdapterIdentifier(UINT, DWORD, D3DADAPTER_IDENTIFIER9*)' without object
   22 |         HRESULT hResult = IDirect3D9::GetAdapterIdentifier(x ,xWord, &pIdentifier);
      |                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:7: build] Error 1

This is my main.cpp file very simple yet still got an error

#include <iostream>
#include <d3d9.h>
#include <D3D9Types.h>
#include <tchar.h>


int main(void)
{
    UINT x; 
    DWORD xWord; 
    D3DADAPTER_IDENTIFIER9 pIdentifier;

    HRESULT hResult = IDirect3D9::GetAdapterIdentifier(x ,xWord, &pIdentifier);
    
    return 0;
}

I am using a Makefile to compile the main file

CC = g++
FILES = main.cpp
OUT_EXE = output
INCLUDES = -ld3d9 -ld3dcompiler -lgdi32 -static -static-libstdc++

build:$(FILES)
    $(CC) $(FILES) $(INCLUDES) -o $(OUT_EXE)

Solution

  • Found this blog that helped me get to this answer

    #include <iostream>
    #include <d3d9.h>
    #include <D3D9Types.h>
    #include <tchar.h>
    #include <string.h>
    
    LPDIRECT3D9       g_pDirect3D = NULL;
    LPDIRECT3DDEVICE9 g_pDirect3D_Device = NULL;
    
    
    int main(void)
    {
        UINT x = 0; // Ordinal number that denotes the display adapter. 
        DWORD xWord = 0 ; 
        D3DADAPTER_IDENTIFIER9 pIdentifier ;
        g_pDirect3D = Direct3DCreate9(D3D_SDK_VERSION);
    
        HRESULT hResult = g_pDirect3D->GetAdapterIdentifier(x, xWord, &pIdentifier);
        
        if (hResult == D3D_OK)
            std::cout << "Successfully created DirectX handle " << std::endl;
        else 
            std::cout << "Failed to create DirectX handle" << std::endl;
        return 0;
    }
    

    Direct3DCreate9 creates a handle to call the functions from