Vanya
Vanya

Reputation: 439

D3DKMTOpenAdapterFromDeviceName and DeviceName

I'm looking for the way to communicate with display driver, and found this function, its a bit poorly documented in msdn. I need to use this, because it will return me the handle which later i can use to display the gpu load in my application. But there is a problem, what i did is i looked in my Device Manager, and copied the value of the "the path to the device instance" in my gpu properties. it looks like so:

PCI\VEN_1002&DEV_6798&SUBSYS_04481043&REV_00\4&72ACCB3&0&0008

Here is the example of D3DKMTOpenAdapterFromDeviceName which i found:

 D3DKMT_OPENADAPTERFROMDEVICENAME name = { _T("\\\\?\\pci#ven_10de&dev_0a2b&subsys_9072104d&rev_a2#4&12796cb&0&0008#{1ca05180-a699-450a-9a0c-de4fbe3ddd89}") };
   HMODULE hGdi32 = LoadLibrary(_T("gdi32.dll"));
   PD3DKMTOpenAdapterFromDeviceName D3DKMTOpenAdapterFromDeviceName = (PD3DKMTOpenAdapterFromDeviceName)GetProcAddress(hGdi32, "D3DKMTOpenAdapterFromDeviceName");
   NTSTATUS status = D3DKMTOpenAdapterFromDeviceName(&name);

In this example they have some GUID at the end of the device #{1ca05180-a699-450a-9a0c-de4fbe3ddd89}. So which GUID from the device manager properties of my GPU i should use? I tried to use like half of the GUIDS from my VideoCard properties in Device Manager and always get - "STATUS_INVALID_PARAMETER"

Upvotes: 2

Views: 884

Answers (1)

forlayo
forlayo

Reputation: 1688

{1ca05180-a699-450a-9a0c-de4fbe3ddd89} is the identifier of GUID_DISPLAY_DEVICE_ARRIVAL

So you can compose your name like:

"\\\\?\\" + deviceName + "#{1ca05180-a699-450a-9a0c-de4fbe3ddd89}"

replacing your "\" for #; example with yours:

"\\\\?\\" + "PCI#VEN_1002&DEV_6798&SUBSYS_04481043&REV_00#4&72ACCB3&0&0008"+"#{1ca05180-a699-450a-9a0c-de4fbe3ddd89}"

And then to find this programatically you can do a COM search like this:

hres = pSvc->ExecQuery(
        bstr_t("WQL"),
        bstr_t("SELECT * FROM Win32_VideoController"),
        WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
        NULL,
        &pEnumerator);

And taking PNPDeviceID which is the string you've found at your Device Manager; take in account of being sure it's your currently in use graphic card, as it's possible to have more than one.

Upvotes: 1

Related Questions