Jump to content
  • Advertisement
Sign in to follow this  

IDirect3DDevice9 and LPDIRECT3DDEVICE9 *solved*

This topic is 4130 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'm having some trouble loading an image in DirectX. I have the device as a IDirect3DDevice9 but the function D3DXCreateTextureFromFile uses LPDIRECT3DDEVICE9. It looks like LPDIRECT3DDEVICE9 is a pointer to IDirect3DDevice9, but how do I convert them? Here's my code, which doesn't work.
objTexture * test = new objTexture( "Blah.png", *D3D_device );
The code for loading...
objTexture::objTexture( const std::string& fname, IDirect3DDevice9 *dev ) : Texture(NULL) // set texture to null originally
{
    HRESULT loaded;
    loaded = D3DXCreateTextureFromFile( dev, // Direct3D Device
                                        fname.c_str(), // File Name
                                        &Texture ); // Texture handle
   if (FAILED(loaded))
   {
      std::string errorstr = "Could not load texture: " + fname;
      WriteToLog( errorstr );
   }
   // this loads the texture and sets the pointer "Texture" to point to that location
}
[Edited by - Gumgo on January 29, 2007 3:54:31 PM]

Share this post


Link to post
Share on other sites
Advertisement
As you said, LPDIRECT3DDEVICE9 is a pointer to IDirect3DDevice9, so why do you think you need to "convert" between LPDIRECT3DDEVICE9 and a pointer to IDirect3DDevice9.

This looks like it might be wrong:
    objTexture * test = new objTexture( "Blah.png", *D3D_device );
...
objTexture::objTexture( const std::string& fname, IDirect3DDevice9 *dev )
What is D3D_device?

Share this post


Link to post
Share on other sites
D3D_device is the device, a IDirect3DDevice9.

When I compile, I get an error that says "error C2664: 'D3DXCreateTextureFromFileA' : cannot convert parameter 1 from 'IDirect3DDevice9 **__w64 ' to 'LPDIRECT3DDEVICE9'"

Share this post


Link to post
Share on other sites
Please, any help?

If it is of any use, the delcaration of D3D_device is

IDirect3DDevice9 *D3D_device = NULL;

and it is later set to be the deivce. Since it is already a pointer, isn't it basically the same as a LPDIRECT3DDEVICE? I tried this:

objTexture * test = new objTexture( "Blah.png", D3D_device );

and then

objTexture::objTexture( const std::string& fname, LPDIRECT3DDEVICE9 dev ) : Texture(NULL)

But it says

"error LNK2019: unresolved external symbol _D3DXCreateTextureFromFileA@12 referenced in function "public: __thiscall objTexture::objTexture(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct IDirect3DDevice9 *)" (??0objTexture@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAUIDirect3DDevice9@@@Z)"

a bunch of weird stuff I can't understand.

EDIT: If I comment out the actual function that LOADS the texture, which is

loaded = D3DXCreateTextureFromFile( dev,
fname.c_str(),
&Texture );

It compiles with no errors...

EDIT: Figured it out. I accidentially forgot to include one of the Direct3D libs.

[Edited by - Gumgo on January 29, 2007 3:15:03 PM]

Share this post


Link to post
Share on other sites
Suggestion: now that you figured out the problem, go through the various attempts you made and figure out why they didn't work, and figure out the reasons for the various errors. C++ errors can be very confusing and if you can learn what they mean and how to interpret them, it will make programming much easier.

As you found out, the correct code is something like this. Remember that LPDIRECT3DDEVICE9 and IDirect3DDevice * are basically interchangeable:
    IDirect3DDevice9 * D3D_device = NULL;
...
objTexture * test = new objTexture( "Blah.png", D3D_device );
...
objTexture::objTexture( const std::string& fname, IDirect3DDevice9 * dev ) : Texture(NULL)
{
HRESULT loaded;
loaded = D3DXCreateTextureFromFile( dev, // Direct3D Device
fname.c_str(), // File Name
&Texture ); // Texture handle
or like this (I prefer not to use the LPDIRECT3DDEVICE9 type):
    LPDIRECT3DDEVICE9 D3D_device = NULL;
...
objTexture * test = new objTexture( "Blah.png", D3D_device );
...
objTexture::objTexture( const std::string& fname, LPDIRECT3DDEVICE9 dev ) : Texture(NULL)
{
HRESULT loaded;
loaded = D3DXCreateTextureFromFile( dev, // Direct3D Device
fname.c_str(), // File Name
&Texture ); // Texture handle

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!