Sign in to follow this  

D3DXCreateTextureFromFileEx

This topic is 4389 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 was working with the given function earlier today: HRESULT WINAPI D3DXCreateTextureFromFileEx( LPDIRECT3DDEVICE9 pDevice, LPCTSTR pSrcFile, UINT Width, UINT Height, UINT MipLevels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, DWORD Filter, DWORD MipFilter, D3DCOLOR ColorKey, D3DXIMAGE_INFO *pSrcInfo, PALETTEENTRY *pPalette, LPDIRECT3DTEXTURE9 *ppTexture ); Please note the last parameter of this function because this is where I was having problems. The function takes a pointer to this data structure. However LPDIRECT3DTEXTURE9 is also a pointer variable so essentially what you have is a pointer to a pointer variable you have to pass in. At first I declared a variable LPDIRECT3DTEXTURE9 * myTex; and I passed this into the function. However, this would cause the function to return an error code of D3D_INVALIDCALL. After several hours I changed the variable to be LPDIRECT3DTEXTURE9 myTex and then I passed in &myTex to the function and this caused it to work. This basically goes against everything I've learned about C/C++ and pointers. The first variable I declared and passed in should have had the same effect as using the addressof operator on the second variable that I ended up passing in. What am I missing here?

Share this post


Link to post
Share on other sites
I'm surpprised that it gave an error code rather then just crashing. The first varible you create is a pointer to a pointer to Direct3D Texture Interface which true is the is the same data type as the last parameter but its a pointer to nothing. Because its still a pointer something and you haven't set it to anything. The function needs a pointer to a varible to assign said varible to the address of the texture interface. This is all kind confusing but hopefully some code will clear it up to. This is how you would pass your first varible if you wanted to use it but it would be redundent.

//This is the pointer to your texture interface (LPDIRECT3DTEXTURE9 is a macro that includes the pointer declaration, the '*'). But this points to nothing yet.
LPDIRECT3DTEXTURE9 PtrToTextureInterface;

//This is the first varible you tryed to use it matches the function parameter but simply declaring it like this leaves it undefined its suppose to point to a pointer but initially it points to nothing thats the key here.
LPDIRECT3DTEXTURE9 *PrtToPtrToTextureInterface;

//So if you wanted to use your pointer to a pointer you need to assign it to something. This assigns it to point to the first varible so now you can use it
PrtToPtrToTextureInterface=&PtrToTextureInterface;

//But this call
PrtToPtrToTextureInterface(...,PrtToPtrToTextureInterface)
//is the same as this call
PrtToPtrToTextureInterface(...,&PtrToTextureInterface)

Hope any of that is comprehensible

Share this post


Link to post
Share on other sites
Yea that makes sense when you think about it. Wish the docs could have conveyed that in a better way though (i.e by explicitly saying that it has to be passed using the addressof operator). Maybe pass by reference would have been a better way to pass it in. oh well :-\

Share this post


Link to post
Share on other sites

This topic is 4389 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