D3DX8 and D3DX9 in one project

Started by
8 comments, last by Dave Hunt 10 years, 9 months ago

Hi,

I want to use D3DX8 and D3DX9 (Sprite and Font class) in one project. Using D3D8 and D3D9 together is not a problem but the X variants have the same function and class name for DX8 and DX9. This causes problems while executing the (test) program.


//D3D8 part
LPDIRECT3DDEVICE8 device;
....
ID3DXSprite *sprite;
D3DXCreateSprite(device, &sprite);
sprite->Release();

//and D3D9 part in an other file
LPDIRECT3DDEVICE9 device;
....
ID3DXSprite *sprite;
D3DXCreateSprite(device, &sprite);
sprite->Release();

The D3D8 part will run fine but the D3D9 part crashes in the D3DXCreateSprite method. I checked the generated assemblercode and it turns out that both D3DXCreateSprite methods are the same so the code tries to initialize the D3DX9 Sprite with the D3DX8 Sprite code what can't work.

I hoped something like this could work but for sure it does not:


namespace D3D8
{
#include <d3dx8.h>
#pragma comment(lib, "d3d8.lib")
#pragma comment(lib, "d3dx8.lib")
}

D3D8::ID3DXSprite *sprite;
D3D8::D3DXCreateSprite(device, &sprite);
sprite->Release();

The compiler doesn't create seperate methods.

Anyone has an idea how I can include both DX versions in one project? One solution could be to dynamicly load the d3dx_....dll and use GetProcAddress for D3DXCreateSprite but I hope there is an "build in" solution.

Thanks for your help!

Advertisement

Why do you need D3DX8? What are the functions in D3DX8 which aren't available in the D3DX9?

Cheers!

it is an overlay for dx apps and should work with DX8 (yeah some older programs use it ;)) and DX9.
Internaly it checks which version the game uses and then uses my DX8 or DX9 renderer.

Sorry to say this, but in VC++ you have no way to tell the compiler "that's the right dll". There are 2 solutions to your problem:

1. GetProcAddress all of D3DX8 needed functions dynamically.

2. Wrap those functions in separate library and static-link.

It's additional work, but probably the only solution.

I tested your second idea 5 minutes before because I thought it would work but now the DX8 part is ignored and the DX9 D3DXCreateSprite gets called for both. Maybe I have done something wrong with it. GetProcAddress with D3DX8 will not work (found it out yesterday) because there isn't a d3dx8_....dll. The provided file in the DX8 SDK is a static library.

I will attach the project and it would be very cool if you could check if I did something wrong.

Create two DLLs that contain the DX functionality you need, one compiled against DX8, the other compiled against DX9. Then have your application dynamically load the appropriate DLL at runtime. Note that your are not dynamically loading DX, only the version of your DLL compiled against the desired DX version.

yes, this would work but I don't want to split this part in different DLLs.

Sorry, but that is the correct way to do it.

Why do you care that they are in different DLLs?

I ended up in this solution. Works fine and without big codechanges but is not portable.

http://stackoverflow.com/questions/10036733/modifying-a-compiled-static-library

Renamed D3DXCreateSprite in the d3dx8 header and library to D3DXCreateSprit8. Now the conflicts are gone.

Thanks for your help anyway :)

I'm confused as to how an outright hack is preferable to a clean and simple solution, but if you're happy, then carry on.

This topic is closed to new replies.

Advertisement