Sign in to follow this  

Can't find where 'CA2W' is defined

This topic is 3653 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[i] = tempMaterials[i].MatD3D;    // get the material info
        material[i].Ambient = material[i].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[i].pTextureFilename),
                                            &texture[i])))
        texture[i] = NULL;    // if there is no texture, set the texture to NULL
      }

Please help! :(

Share this post


Link to post
Share on other sites
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[i] = (TCHAR) szSrcStr[i];

// 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

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