Last active
June 17, 2022 09:07
-
-
Save redmcg/5b11d2d18ff29da5d9d4886b2e1699a1 to your computer and use it in GitHub Desktop.
Get number of D3D9 adapters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
compile with: x86_64-w64-mingw32-g++ d3d9Test.cpp