Jump to content
  • Advertisement
Sign in to follow this  
maya18222

LPSTR to wchar

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

hi, Im wondering how i would go about using the following std::wstring strPath; strPath.append(d3dxMaterials.pTextureFilename); where d3dxMaterials is of type typedef struct _D3DXMATERIAL { D3DMATERIAL9 MatD3D; LPSTR pTextureFilename; } D3DXMATERIAL; typedef D3DXMATERIAL *LPD3DXMATERIAL; so basically, i want to convert a LPSTR to be used with a wstring, i believe that LPSTR is a char pointer, from looking at this typedef __nullterminated CHAR *NPSTR, *LPSTR, *PSTR; but why has it got the '*' in front?

Share this post


Link to post
Share on other sites
Advertisement
There's multiple declarations in one line, separated by commatas. So if they don't put the * (for pointer) in front of every type only the first one will be a pointer, the others plain char's. One of the nasty possible ambiguities of C/C++.

Here's a snippet i'm using to convert std::string to std::wstring. That should work with LPSTR as well:


std::wstring ToWString( const std::string& strText )
{
std::wstring wstrResult;

wstrResult.resize( strText.length() );

typedef std::codecvt<wchar_t, char, mbstate_t> widecvt;

std::locale locGlob;

std::locale::global( locGlob );

const widecvt& cvt( std::use_facet<widecvt>( locGlob ) );

mbstate_t State;

const char* cTemp;
wchar_t* wTemp;

cvt.in( State,
&strText[0], &strText[0] + strText.length(), cTemp,
(wchar_t*)&wstrResult[0], &wstrResult[0] + wstrResult.length(), wTemp );

return wstrResult;
}

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!