UTF8変換
厳密ではないけどマルチバイト環境でもunicode環境でも使えるUTF8に変換する関数。
マルチバイト環境の時にMultiByteToWideCharとWideCharToMultiByteを
使わなければいけないのはどうにかならないものか。
int GetUTF8String(const TCHAR *pInBuf, char *pOutBuf) { int strLength; #ifdef _UNICODE strLength = ::WideCharToMultiByte(CP_UTF8, 0, pInBuf, -1, pOutBuf, MAX_PATH, NULL, NULL); #else wchar_t wBuf[MAX_PATH]; ::MultiByteToWideChar(CP_ACP, 0, pInBuf, -1, wBuf, MAX_PATH); strLength = ::WideCharToMultiByte(CP_UTF8, 0, wBuf, -1, pOutBuf, MAX_PATH, NULL, NULL); #endif return strLength - 1; // 文字数を返す }