-1

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)
netrunner
  • 45
  • 7
  • 2
    `GetAdapterIdentifier` is a non-static member function of `IDirect3D9` interface. You need to instantiate an object that implements this interface first by invoking `Direct3DCreate9` function. – user7860670 Mar 20 '22 at 19:11
  • 2
    And if you don't understand something so fundamental to the language it would likely better serve you to step back and learn the language first, particularly when it comes to C++ there are a huge number of hurdles to jump before you are proficient to write useful code. – SoronelHaetir Mar 20 '22 at 22:08

1 Answers1

1

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

netrunner
  • 45
  • 7
  • 1
    You are missing the error condition of ``g_pDirect3D`` coming back NULL. Also, why are you wanting to use legacy DIrect3D 9? In any case, you should read [this Microsoft Docs](https://learn.microsoft.com/en-us/windows/win32/prog-dx-with-com) page. – Chuck Walbourn Mar 21 '22 at 05:02
  • 1
    Direct3D 11 is a better place to start for sure these days. Good luck! You may find the [DirectX Tool Kit tutorials](https://github.com/microsoft/DirectXTK/wiki/Getting-Started) useful. – Chuck Walbourn Mar 22 '22 at 19:33