Archived

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

nicho_tedja

Unicode -> ANSI, ANSI -> Unicode

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