这个参数一的作用是什么?有人说是要转换的目标codepage
但我试过后不是这样的.而msdn里说得也不清不楚的.
它只说be used to perform the conversion,没说是源codepage还是目标codepage例如,如果我的工程用多字符集
char *pstr="一二三";
int len=MultiByteToWideChar(CP_UTF8,0,str,-1,0,0);//请求WCHAR字符数
len等于2(这里是错误的,正确应该是4,如果CP_UTF8改CP_ACP就正常,说明不是目标codepage)那么就试试会不会是源codpage呢,结果:
WCHAR *pwstr=L"一二三";
int len=WideCharToMultiByte(CP_UTF8,0,pwstr,-1,0,0,NULL,NULL);//请求char字节数
len等于10(说明是错误的,正确应该是7)然后我想是否和工程的字符集有关,我改为unicode字符集
结果还是发生同样的错误.最后的结果是不知到它有什么用.只要用CP_ACP就OK了.PS:如不会是于系统编码有关呢??
但我试过后不是这样的.而msdn里说得也不清不楚的.
它只说be used to perform the conversion,没说是源codepage还是目标codepage例如,如果我的工程用多字符集
char *pstr="一二三";
int len=MultiByteToWideChar(CP_UTF8,0,str,-1,0,0);//请求WCHAR字符数
len等于2(这里是错误的,正确应该是4,如果CP_UTF8改CP_ACP就正常,说明不是目标codepage)那么就试试会不会是源codpage呢,结果:
WCHAR *pwstr=L"一二三";
int len=WideCharToMultiByte(CP_UTF8,0,pwstr,-1,0,0,NULL,NULL);//请求char字节数
len等于10(说明是错误的,正确应该是7)然后我想是否和工程的字符集有关,我改为unicode字符集
结果还是发生同样的错误.最后的结果是不知到它有什么用.只要用CP_ACP就OK了.PS:如不会是于系统编码有关呢??
解决方案 »
- 程序打包后在没装VC的机子上运行不了
- 指针和long的转化
- 往CmainFrame类里添加一个消息函数与往CmyView类里添加一个消息函数有什么不同?
- 太郁闷了,这个问题困挠我半天了
- 我要下一个DLL传输文件,其中用到CAsyncSocket类.帮忙说说做DLL和做EXE有什么方面不同..谢谢..
- com中函数的参数可以传递结构体吗?
- ●有这样一个问题,可能很常见,大G们帮忙看看?怎样取得浮动窗体的指针呢???
- 我想问一个关于CTreeCtrl的问题
- VC++用ClassWizard建立对话框类出现的一个疑问。
- mfc单文档分割视图的问题
- 接VC或C/C++得项目做(锻炼自己免费做)
- [求]哪位有VC++数据库系统开发案例精选,明日科技的光盘,可否将例子发上来?
int MultiByteToWideChar(uCodePage, dwFlags, lpMultiByteStr,
cchMultiByte, lpWideCharStr, cchWideChar) UINT uCodePage; /* codepage */
DWORD dwFlags; /* character-type options */
LPCSTR lpMultiByteStr; /* address of string to map */
int cchMultiByte; /* number of characters in string */
LPWSTR lpWideCharStr; /* address of wide-character buffer */
int cchWideChar; /* size of wide-character buffer */
The first parameter, uCodePage, specifies the codepage to be used when performing the conversion. This discussion applies to the first parameter of WideCharToMultiByte() as well. The codepage can be any valid codepage number. It is a good idea to check this number with IsValidCodepage(), even though MultiByteToWideChar() returns an error if an invalid codepage is used. The codepage may also be one of the following values: CP_ACP ANSI codepage
CP_OEMCP OEM (original equipment manufacturer) codepage
CP_ACP instructs the API to use the currently set default Windows ANSI codepage. CP_OEMCP instructs the API to use the currently set default OEM codepage. If Win32 ANSI APIs are used to get filenames from a Windows NT system, use CP_ACP when converting the string. Windows NT retrieves the name from the physical device and translates the OEM name into Unicode. The Unicode name is translated into ANSI if an ANSI API is called, then it can be translated back into Unicode with MultiByteToWideChar(). If filenames are being retrieved from a file that is OEM encoded, use CP_OEMCP instead. MORE INFORMATION
When an application calls an ANSI function, the FAT/HPFS file systems will call AnsiToOem(); however, if an ANSI character does not exist in an OEM codepage, the filename will not be representable. In these cases, SetFileApisToOEM() should be called to prevent this problem by setting a group of the Win32 APIs to use the OEM codepage instead of the ANSI codepage.
CP_UTF8只能从宽字符和单字符之间转换,且UTF8是汉字有三个字符组成的