유니 코드를 컴파일 및 ANSI로 변환이 작동하는 표시 나
(http://support.microsoft.com/kb/138813에서 수정이) :
HRESULT UnicodeToAnsi(LPCOLESTR pszW, LPSTR* ppszA){
ULONG cbAnsi, cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (pszW == NULL)
{
*ppszA = NULL;
return NOERROR;
}
cCharacters = wcslen(pszW)+1;
cbAnsi = cCharacters*2;
*ppszA = (LPSTR) CoTaskMemAlloc(cbAnsi);
if (NULL == *ppszA)
return E_OUTOFMEMORY;
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;
}
사용법 :
LPSTR pszstrA;
UnicodeToAnsi(my_unicode_string.Buffer, &pszstrA);
cout << "My ansi string: (" << pszstrA << ")\r\n";
"NULL TERMINATED STRING"이라고 말하면 null로 끝나는 wchar_t 문자열 또는 null로 끝나는 ASCII/멀티 바이트 문자열을 의미합니까? –