|
1.¿ä¾à Anis ¹®ÀÚ¿°ú Unicode ¹®ÀÚ¿À» ¼·Î ¹Ù²Ù´Â ÇÔ¼ö¸¦ ¸¸µé¾î º¾´Ï´Ù. 2.º»¹® COM ÇÁ·Î±×·¡¹ÖÀ» ÇÏ´Ùº¸¸é, BSTR °úÀÇ È£È¯¼ºÀ» ÀÌ·ç±â À§Çؼ Ansi ¹®ÀÚ¿À» Unicode ¹®ÀÚ¿·Î ±×¸®°í ±× ¹Ý´ëÀÇ ¹®ÀÚ¿ º¯È°¡ ÇÊ¿äÇÑ °æ¿ì°¡ ÀÖ½À´Ï´Ù. ÀÌ·± °æ¿ì À¯¿ëÇÏ°Ô »ç¿ëÇÒ ¼ö ÀÖ´Â µÎ°¡Áö ÇÔ¼ö, AnsiToUnicode & UnicodeToAnsi ÇÔ¼ö¸¦ ¸¸µé¾î º¸µµ·Ï ÇϰڽÀ´Ï´Ù. 3.¿¹Á¦
/*
* AnsiToUnicode converts the ANSI string pszA to a Unicode string
* and returns the Unicode string through ppszW. Space for the
* the converted string is allocated by AnsiToUnicode.
*/
HRESULT __fastcall AnsiToUnicode(LPCSTR pszA, LPOLESTR* ppszW)
{
ULONG cCharacters;
DWORD dwError;
// ÀÔ·ÂÇÑ °ªÀÌ NULL À̸é return ÇÕ´Ï´Ù.
if (NULL == pszA)
{
*ppszW = NULL;
return NOERROR;
}
// Unicode ·Î ÇÒ´çµÉ ¹®ÀÚ¿ÀÇ ±æÀ̸¦ ±¸ÇÕ´Ï´Ù.
cCharacters = strlen(pszA)+1;
// Unicode ¹®ÀÚ¿À» À§Çؼ CoTaskMemAlloc() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿©
// ¹®ÀÚ¿À» ÇÒ´çÇÕ´Ï´Ù.
*ppszW = (LPOLESTR) CoTaskMemAlloc(cCharacters*2);
if (NULL == *ppszW)
return E_OUTOFMEMORY;
// Unicode ·Î ¹Ù²ß´Ï´Ù.
if (0 == MultiByteToWideChar(CP_ACP, 0, pszA, cCharacters,
*ppszW, cCharacters))
{
dwError = GetLastError();
CoTaskMemFree(*ppszW);
*ppszW = NULL;
return HRESULT_FROM_WIN32(dwError);
}
return NOERROR;
}
/*
* UnicodeToAnsi converts the Unicode string pszW to an ANSI string
* and returns the ANSI string through ppszA. Space for the
* the converted string is allocated by UnicodeToAnsi.
*/
HRESULT __fastcall UnicodeToAnsi(LPCOLESTR pszW, LPSTR* ppszA)
{
ULONG cbAnsi, cCharacters;
DWORD dwError;
// ÀÔ·Â °ªÀÌ NULL À̸é return
if (pszW == NULL)
{
*ppszA = NULL;
return NOERROR;
}
cCharacters = wcslen(pszW)+1;
cbAnsi = cCharacters*2;
*ppszA = (LPSTR) CoTaskMemAlloc(cbAnsi);
if (NULL == *ppszA)
return E_OUTOFMEMORY;
// ANSI ¹®ÀÚ¿·Î ¹Ù²ß´Ï´Ù.
if (0 == WideCharToMultiByte(CP_ACP, 0, pszW, cCharacters, *ppszA,
cbAnsi, NULL, NULL))
{
dwError = GetLastError();
CoTaskMemFree(*ppszA);
*ppszA = NULL;
return HRESULT_FROM_WIN32(dwError);
}
return NOERROR;
}
4.Âü°í Knowledge Base : Q138813 - 2001.08.13 Smile Seo - |