Jump to content
  • Advertisement
Sign in to follow this  
justcallmedrago

Can't find where 'CA2W' is defined

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

My problem is the same as the person here: http://www.gamedev.net/community/forums/topic.asp?topic_id=440633 That is, I can't find CA2W anywhere!! It's not it atlbase.h or atlconv.h and I can't find the answer anywhere on the internet; not even at MSDN, where all it says is "Required header: atlconv.h" I am using directxtutorial.com to get me started. Here is the code that calls CA2W. It is from the tutorial "Loading Textured Meshes" under Direct3D:
    for(DWORD i = 0; i < numMaterials; i++)    // for each material...
    {
        material = tempMaterials.MatD3D;    // get the material info
        material.Ambient = material.Diffuse;    // make ambient the same as diffuse
        USES_CONVERSION;    // allows certain string conversions
        // if there is a texture to load, load it
        if(FAILED(D3DXCreateTextureFromFile(d3ddev,
                                            CA2W(tempMaterials.pTextureFilename),
                                            &texture)))
        texture = NULL;    // if there is no texture, set the texture to NULL
      }

Please help! :(

Share this post


Link to post
Share on other sites
Advertisement
It's just my guess, but CA2W function probably converts a regular string into wide-character string, and returns a pointer to the converted string. D3DXCreateTextureFromFile takes LPCTSTR for its second parameter, and D3DXMATERIAL structure contains LPSTR data type.

So you can actually implement your own CA2W function, using dynamic allocation and converting from one byte character string into wide-character string.


And here's a thread I found on MSDN forum. You might wanna take a look.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2098323&SiteID=1

Share this post


Link to post
Share on other sites
Um... That's probably what I'd do if I was better at programming. I won't be able to figure out how to do that for a while. What I'd really like is a correct atlconv.h that has CA2W defined in it, since mine doesn't for some reason, even though it should.

Thanks, but that didn't help too much. :/

Share this post


Link to post
Share on other sites
LPTSTR CA2W( LPSTR szSrcStr )
{
// iStrLen = Length of the original strength, *szResult = pointer to the converted stirng
int iStrLen;
TCHAR *szResult;

// Null point passed? Return NULL
if( szSrcStr == NULL )
return NULL;

// Get the Source String Length
iStrLen = (int) strlen( (char *) szSrcStr);

// Dynamically allocate memory for szResult
szResult = new TCHAR[ iStrLen + 1 ];

// Iterate through each character and Copy the String
for( int i = 0; i < iStrLen + 1; i++ )
szResult = (TCHAR) szSrcStr;

// Return the pointer to the dynamically allocated string.
return szResult;
}

I just wrote that really quick. Try it and let me know how that works.

*You need to include <windows.h> to use this code. And I didn't write the whole system to deallocate the converted strings when the application terminates.

Share this post


Link to post
Share on other sites
Thanks that worked! But I don't think your function works (the plane is not textured)

I tried sticking a breakpoint in there right after the texture string was modified, but when I run the code, I can't get to VStudio without closing the game window, which makes VS get out of build/debug(?) mode so I can't check what the variables are.

Also, could anyone explain why commenting that out still works? Why can that be excluded and what was it's purpose anyway? If anyone has a general explanation why sometimes just taking things out works just as well, that'd be good too!

Share this post


Link to post
Share on other sites
Quote:
Original post by justcallmedrago
But I don't think your function works (the plane is not textured)


I wonder why my function failed. Try using FileMon utility to see the details of files accessed by the program.

Share this post


Link to post
Share on other sites
NEVERMIND! Sorry, the texture files were one folder too deep!! :X :X :X :X

Thanks a lot for the code, and how would I implement "deallocation"? i've heard that memory leaks are really bad.

Share this post


Link to post
Share on other sites
Just copying narrow characters to wide characters may not convert the string properly. Try using mbstowcs().

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!