Sign in to follow this  

Avoinding the use of d3d9.lib and others

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 somewhere
HMODULE 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 this post


Link to post
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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