Skip to content

Instantly share code, notes, and snippets.

@redmcg
Last active June 17, 2022 09:07
Show Gist options
  • Select an option

  • Save redmcg/5b11d2d18ff29da5d9d4886b2e1699a1 to your computer and use it in GitHub Desktop.

Select an option

Save redmcg/5b11d2d18ff29da5d9d4886b2e1699a1 to your computer and use it in GitHub Desktop.
Get number of D3D9 adapters
// compile with: x86_64-w64-mingw32-g++ d3d9Test.cpp
#include <d3d9.h>
#include <stdio.h>
int main(int argc, char **argv) {
HRESULT hr = E_FAIL;
HMODULE libHandle = NULL;
// Manually load the d3d9.dll library.
libHandle = LoadLibrary("d3d9.dll");
if (libHandle != NULL) {
// Define a function pointer to the Direct3DCreate9Ex function.
typedef HRESULT(WINAPI * LPDIRECT3DCREATE9EX)(UINT, IDirect3D9Ex **);
// Obtain the address of the Direct3DCreate9Ex function.
LPDIRECT3DCREATE9EX Direct3DCreate9ExPtr = NULL;
Direct3DCreate9ExPtr =
(LPDIRECT3DCREATE9EX)GetProcAddress(libHandle, "Direct3DCreate9Ex");
if (Direct3DCreate9ExPtr != NULL) {
// Direct3DCreate9Ex is supported.
hr = S_OK;
IDirect3D9Ex *pD3D = NULL;
if (FAILED(hr = Direct3DCreate9ExPtr(D3D_SDK_VERSION, &pD3D))) {
printf("Failed\n");
} else {
UINT adapterCount = pD3D->GetAdapterCount();
printf("You have %d adapter(s):\n", adapterCount);
for (UINT i = 0; i < adapterCount; i++) {
D3DADAPTER_IDENTIFIER9 id;
pD3D->GetAdapterIdentifier(i, 0, &id);
printf(" - %s (%s)\n", id.DeviceName, id.Description);
}
}
} else {
// Direct3DCreate9Ex is not supported on this
// operating system.
hr = ERROR_NOT_SUPPORTED;
printf("Not supported\n");
}
// Free the library.
FreeLibrary(libHandle);
}
return hr;
}
@redmcg
Copy link
Author

redmcg commented Jun 9, 2022

compile with: x86_64-w64-mingw32-g++ d3d9Test.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment