Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

nicho_tedja

Unicode -> ANSI, ANSI -> Unicode

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

Is there a function (Win32 or STL or CRT) to convert a string from ANSI to Unicode and vice versa? I''ve searched through MSDN, and stupidly I didn''t find anything that talk about it. Can someone please tell me the function?
My compiler generates one error message: "Doesn''t compile." -Albert Tedja-

Share this post


Link to post
Share on other sites
Advertisement
Sure - and here''s a couple of functions too

WideCharToMultiByte :: Unicode -> Ansi
MultiByteToWideChar :: Ansi -> Unicode


  
// ----------------------------------------------------------------------------

//

//

BOOL UnicodeToAnsi(
LPWSTR pszwUniString,
LPSTR pszAnsiBuff,
DWORD dwAnsiBuffSize
)
{
int iRet = 0;
iRet = WideCharToMultiByte(
CP_ACP,
0,
pszwUniString,
-1,
pszAnsiBuff,
dwAnsiBuffSize,
NULL,
NULL
);
return ( 0 != iRet );
}


// ----------------------------------------------------------------------------

//

//

BOOL AnsiToUnicode(
LPSTR pszAnsiString,
LPWSTR pszwUniBuff,
DWORD dwUniBuffSize
)
{

int iRet = 0;
iRet = MultiByteToWideChar(
CP_ACP,
0,
pszAnsiString,
-1,
pszwUniBuff,
dwUniBuffSize
);

return ( 0 != iRet );
}

Share this post


Link to post
Share on other sites

  • 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!