Sign in to follow this  

Dynamic runtime linking of DirectX 11

Recommended Posts

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 ?

Share this post

Link to post
Share on other sites
[quote name='yckx' timestamp='1313461136' post='4849667']
Apparently the same way, according to [url=""]this AppHub thread[/url].

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 :( ):

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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this