Avoinding the use of d3d9.lib and others

Started by
6 comments, last by busytree 17 years, 7 months ago
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
Advertisement
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.
Using delayed loading should fix this, and you won't have to worry about manually loading the DLL and not having D3DX. See here for info.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
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?
Quote:Original post by Torpedo
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?
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.
Didn't know that Microsoft advices not to use DInput.
What should an aplication use then?
The window message loop? I hope not!
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?
I had this problem. I had two projects that used Dinput. One worked flawlessly and other kept popping up error on c_dfIDkeyboard. So what I did, I copied the first project that worked and cleared it, and pasted the second project code unto it. It worked. If this is the first time, then make a new project in different folder or drive. Or just make different project and start from scratch.

This topic is closed to new replies.

Advertisement