Dynamic runtime linking of DirectX 11

Started by
1 comment, last by griffin77 12 years, 8 months ago
Is there anyway to dynamically link against the DirectX 11 DLLs in a way that's error tolerant ? i.e. I can detect if the d3d11.dll exists on a system and gracefully fail

I'm assuming d3d11.dll won't exist if you don't have a DirectX 11 gfx card/driver installed ? I can use delayed loading to mitigate the problem, but I'll still get a runtime error when I try and call D3D11CreateDevice and it doesn't exist.

For a simple C API I could use LoadLibrary to dynamically bind APIs at run time e.g. for imagehlp.dll:

hImagehlpDll = LoadLibraryA( "imagehlp.dll" );
if ( hImagehlpDll == NULL )
return 0;//DLL not found gracefully exit

//Bind functions as C callback functions that can then be used as if they were statically linked C functions
pSGLFA = (tSGLFA) GetProcAddress( hImagehlpDll, "SymGetLineFromAddr" );

//Execute the function
pSGLFA( hProcess, (DWORD)addrPC, &offsetFromSymbol, &Line )


But how do I do this for a complicated C++ API like DirectX 11 ?
Advertisement
Apparently the same way, according to this AppHub thread.

Apparently the same way, according to this AppHub thread.


Thanks for that. There is in interesting link from MS in that thread that talks about a DLL from Microsoft that does alot of this (but its an separate DLL you'd need to distribute with your app :( ):
http://msdn.microsof...y/ee416644.aspx

I actually came up with a pretty simple solution to this. I use LoadLibrary to verify if the d3d11.dll exists, but I never use it. I just gracefully exit if its not found without calling any DX functions. As the DX DLL is delay-loaded this works fine, and if DirectX 11 does not exist on the computer my code is run on, then none of the delay loaded functions are executed, and I don't hit any errors.

This topic is closed to new replies.

Advertisement