D3DXCreateTextureFromFileEx

Started by
3 comments, last by axv4745 18 years, 4 months ago
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?
Advertisement
Did you try &(*myTex) on the LPDIRECT3DTEXTURE9* ?

Also, have you tried running against the debug runtimes? they tend to be pretty good at explaining what it doesn't like [smile]

Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

... you have declared a pointer to a pointer ( **x)

so *x has no memory jet, and thats why the function cannot use your **x ...

as jollyjeffers said use :

LPDIRECT3DTEXTURE9 myTex;

and pass &myTex to the function
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
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 :-\

This topic is closed to new replies.

Advertisement