Windows函数MultiByteToWideChar将多字节字符串转换为宽字符字符串。
int
WINAPI
MultiByteToWideChar(
__in UINT CodePage,
__in DWORD dwFlags,
__in LPCSTR lpMultiByteStr,
__in int cbMultiByte,
__out_ecount_opt(cchWideChar) LPWSTR lpWideCharStr,
__in int cchWideChar);
参数: CodePage
//
// Code Page Default Values.
//
#define CP_ACP 0 // default to ANSI code page
#define CP_OEMCP 1 // default to OEM code page
#define CP_MACCP 2 // default to MAC code page
#define CP_THREAD_ACP 3 // current thread's ANSI code page
#define CP_SYMBOL 42 // SYMBOL translations
#define CP_UTF7 65000 // UTF-7 translation
#define CP_UTF8 65001 // UTF-8 translation
参数 dwFlags:参数允许我们进行额外的控制,它会影响带变音符号(比如重音)的字符,但是,一般情况下不使用, 所以dwFlags一般为 0.
参数:lpMultiByteStr 多字节字符的地址。
参数 :cbMultiByte多字节字符串的长度(字节数)。如果 传给cbMultiByte参数是-1,函数便可自动判断字符串的长度。
参数 : lpWideCharStr 是宽字符的存放地址
参数 : cchWideChar是宽字符的长度。
再使用的时候,
两次调用 MultiByteToWideChar();
第一次调用的时候,
int dwLength= MultiByteToWideChar(CP_ACP,0,chMax, -1, NULL,0);
wChar chNewWide[dwLength];
MultiByteToWideChar(CP_ACP, 0 , chMax, -1, chNewWide, sizeof(WCHAR) *dwLength);
Next: 来讨论 WideCharToMultiByte这个函数
int
WINAPI
WideCharToMultiByte(
__in UINT CodePage,
__in DWORD dwFlags,
__in_opt LPCWSTR lpWideCharStr,
__in int cchWideChar,
__out_bcount_opt(cbMultiByte) LPSTR lpMultiByteStr,
__in int cbMultiByte,
__in_opt LPCSTR lpDefaultChar,
__out_opt LPBOOL lpUsedDefaultChar);
这两个 函数差不多的。就不再解释了,直接写程序。
dwLength = WideCharToMultiByte(CP_ACP, 0, chC, -1, NULL, 0, NULL, NULL);
char *chD = NULL;
chD = (char *)malloc(dwLength);
dwLength = WideCharToMultiByte(CP_ACP, 0, chC, -1, chD, dwLength, NULL, NULL );今天先讲到这里吧。