밥줄팁/C UnicodeToUTF8 변환하기. ggil 2009. 9. 2. 21:39 Sqlite3 소스코드에 있는 내용입니다. #include /* ** Convert microsoft unicode to UTF-8. Space to hold the returned string is ** obtained from malloc(). */ static char *unicodeToUtf8(const WCHAR *zWideFilename, int &nUTFLen){ int nByte; char *zFilename; nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0); nUTFLen = nByte; zFilename = (char*)malloc( nByte ); if( zFilename==0 ){ return 0; } nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte, 0, 0); if( nByte == 0 ){ free(zFilename); zFilename = 0; } return zFilename; } int _tmain(int argc, _TCHAR* argv[]) { TCHAR *szString = L"12345한글漢字ABCD"; int nUTFLen; char* szUTF8 = unicodeToUtf8(szString,nUTFLen); if (szUTF8) { free(szUTF8); szUTF8 = NULL; } return 0; } 저작자표시 비영리 변경금지 (새창열림)