• 15
• 15
• 11
• 9
• 10

# Avoinding the use of d3d9.lib and others

This topic is 4203 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to avoid the use of d3d9.lib in project. That file is only needed for the Direct3DCreate9() function. The problem is that if I run the game in a computer that does not have DX9 installed I will get the error d3d9.dll not found. I want to use CoCreateInstance() to avoid Direct3DCreate9(). The problem is that I can't find the CLSID_Direct3D9 identifier to use in the call to CoCreateInstance(). Does anyone knows what value should be used? Ty

##### Share on other sites
There's an easier way; try to load the D3D DLL at runtime:
typedef IDirect3D9* (*LPDirect3DCreate9)(UINT SDKVersion);// In some function somewhereHMODULE hDll = LoadLibrary("d3d9.dll");if(!hDll){   // Can't load DLL, DX9 probably not installed}else{   LPDirect3DCreate9 pfnCreate = (LPDirect3DCreate9)GetProcAddress(hDll, "Direct3DCreate9");   if(!pfnCreate)   {      // d3d9.dll exists, but Direct3DCreate9 doesn't. DLL isn't the d3d9 one   }   else   {      IDirect3D9* pD3D = pfnCreate(D3D_SDK_VERSION);      // Use pD3D   }}

You should ideally keep the hDll around and call FreeLibrary(hDll) at shutdown, but Windows will do that for you, so there's no real need to.

The only problem with doing this (Or the CoCreateInstance method) is that you can't (easily) use D3DX, since most of the D3DX functions are in another DLL.

##### Share on other sites
Thanks, it worked perfectly.

As for DirectInput, I get unresolved external for the global var c_dfDIKeyboard defined in DInput.lib.
I can't see how I can get the variable from the DLL if I use LoadLibrary().

I'm thinking about inspected the c_dfDIKeyboard structure in debug mode, create a new var with the same data and use that var instead of dfDIKeyboard . How stupid is this?

##### Share on other sites
Quote:
 Original post by TorpedoThanks, it worked perfectly.As for DirectInput, I get unresolved external for the global var c_dfDIKeyboard defined in DInput.lib.I can't see how I can get the variable from the DLL if I use LoadLibrary().I'm thinking about inspected the c_dfDIKeyboard structure in debug mode, create a new var with the same data and use that var instead of dfDIKeyboard . How stupid is this?
Just linking to dxguid.lib (Or is it dxguids.lib?) will solve this. It's a static lib and won't drag in any DLLs.
Alternatively, #define INIT_GUID before including the DInput header.

It might be worth noting that Microsoft advises against using DirectInput altogether now.

##### Share on other sites
Didn't know that Microsoft advices not to use DInput.
What should an aplication use then?
The window message loop? I hope not!

##### Share on other sites
I've removed dinput.lib and defined INIT_GUID before including dinput.h, but I'm still having the unresolved external error for c_dfDIKeyboard.
I realy don't see how could this resolve the problem.
c_dfDIKeyboard is defined in dinput.h as an extern, and I din't find that var defined in any other header.

Could the solution be to include dinput.lib instead of dinput8.lib, and use LoadLibrary() and GetProcAddress() for dinput8.dll?