MultiByteToWideChar的用法
MultiByteToWideChar:
1)調用MultiByteToWideChar,爲lpWideCharStr參數傳入待轉換的字符串,爲cchWideChar參數傳入0,爲cchMultiByte參數傳入-1;
2)分配一塊足夠容納轉換後Unicode字符串的內存,它的大小是上一個MultiByteToWideChar調用的返回值乘以sizeof(wchar_t);
3)再次調用MultiByteToWideChar,這一次將緩衝區地址作爲lpWideCharStr參數的值傳入,將第一次MultiByteToWideChar調用的返回值乘以sizeof(wchar_t) 後得到的大小的作爲cchWideChar參數的值傳入;
4)使用轉換後的字符串;
5)釋放Unicode字符串佔用的內存塊。
string strTem = strIDInor.strGender + strIDInor.strNation + strIDInor.strDateOfBirth;
wcsLen = ::MultiByteToWideChar(CP_ACP, NULL, strTem.c_str(), strlen(strTem.c_str()), NULL, 0);
wszString = new wchar_t[wcsLen + 1];
::MultiByteToWideChar(CP_ACP, NULL, strTem.c_str(), strlen(strTem.c_str()), wszString, wcsLen);
cFile.Write(wszString, wcsLen * sizeof(wchar_t));
delete[] wszString;