Search code examples
c++directxdirectx-11directx-9directx-10

Dll injection overlay DirectX version


I'm working on screenshot application for full-screen DirectX games. But there is one problem - for every version of DirectX there is own way to make screenshot (as far as I understand).

So the question is how to determine DirectX version of application which I injects with my DLL from this DLL?


Solution

  • One simple trick to determine the actual DirectX version in my DirectX hooks is to call GetModuleHandle for each of the dx dlls. For instance:

    HINSTANCE hD3D11 = GetModuleHandle(TEXT("D3D11.DLL"));
    if (hD3D11)
    {
        // DirectX 11 dll is loaded, so we can hook D3D11CreateDeviceAndSwapChain and/or D3D11CreateDevice
    }
    

    And the same or similar for D3D10.dll and D3D9.dll. I think the best way is to try GetModuleHandle in the following order: d3d11.dll, d3d10.dll and d3d9.dll. This approach works well for the DX hooks I created. I hope it will work for you too, or you have to adjust it for your purposes. Of course you should first inject the above code that checks the DX version and after that decide which DXhook dll to inject according to the version.