WideCharToMultiByte,MultiByteToWideChar

 

         char  temp[ 1024 ] = { 0 };
        ZeroMemory(temp, 
sizeof (temp));
        
int  len  =  WideCharToMultiByte(CP_ACP,  0 , vtProp.bstrVal,  - 1 , temp,  sizeof (temp), NULL, NULL);

 

MultiByteToWideChar(CP_ACP,  0 , szDrive,  - 1 , m_RootDirectory,  sizeof (m_RootDirectory)); 

 

int WideCharToMultiByte(
UINT CodePage,            // code page
  DWORD dwFlags,            // performance and mapping flags
  LPCWSTR lpWideCharStr,    // wide-character string
  int cchWideChar,          // number of chars in string.
  LPSTR lpMultiByteStr,     // buffer for new string
  int cbMultiByte,          // size of buffer
  LPCSTR lpDefaultChar,     // default for unmappable chars
  LPBOOL lpUsedDefaultChar  // set when default char used
);

 

Parameters
CodePage
[in] Specifies the code page used to perform the conversion. This parameter can be given the value of any code page that is installed or available in the system. For a list of code pages, see Code Page Identifiers. You can also specify one of the following values.
ValueMeaning
CP_ACPANSI code page
CP_MACCPMacintosh code page
CP_OEMCPOEM code page
CP_SYMBOLWindows 2000/XP: Symbol code page (42)
CP_THREAD_ACPWindows 2000/XP: Current thread's ANSI code page
CP_UTF7Windows 98/Me, Windows NT 4.0 and later: Translate using UTF-7. When this is set, lpDefaultChar and lpUsedDefaultChar must be NULL
CP_UTF8Windows 98/Me, Windows NT 4.0 and later: Translate using UTF-8. When this is set, dwFlags must be zero and both lpDefaultChar and lpUsedDefaultChar must be NULL.

Windows 95: Under the , WideCharToMultiByte also supports CP_UTF7 and CP_UTF8.

dwFlags
[in] Specifies the handling of unmapped characters. The function performs more quickly when none of these flags is set. The following flag constants are defined.
ValueMeaning
WC_NO_BEST_FIT_CHARSWindows 98/Me and Windows 2000/XP: Any Unicode characters that do not translate directly to multibyte equivalents are translated to the default character (see lpDefaultChar parameter). In other words, if translating from Unicode to multibyte and back to Unicode again does not yield the exact same Unicode character, the default character is used.

This flag can be used by itself or in combination with the other dwFlag options.

WC_COMPOSITECHECKConvert composite characters to precomposed characters.
WC_DISCARDNSDiscard nonspacing characters during conversion.
WC_SEPCHARSGenerate separate characters during conversion. This is the default conversion behavior.
WC_DEFAULTCHARReplace exceptions with the default character during conversion.

When WC_COMPOSITECHECK is specified, the function converts composite characters to precomposed characters. A composite character consists of a base character and a nonspacing character, each having different character values. A precomposed character has a single character value for a base/nonspacing character combination. In the character , the e is the base character, and the accent grave mark is the nonspacing character.

When an application specifies WC_COMPOSITECHECK, it can use the last three flags in this list (WC_DISCARDNS, WC_SEPCHARS, and WC_DEFAULTCHAR) to customize the conversion to precomposed characters. These flags determine the function's behavior when there is no precomposed mapping for a base/nonspace character combination in a wide-character string. These last three flags can only be used if the WC_COMPOSITECHECK flag is set.

The function's default behavior is to generate separate characters (WC_SEPCHARS) for unmapped composite characters.

For the code pages in the following table, dwFlags must be zero, otherwise the function fails with ERROR_INVALID_FLAGS.

50220

50221

50222

50225

50227

50229

52936

54936

57002 through 57011

65000 (UTF7)

65001 (UTF8)

42 (Symbol)


lpWideCharStr
[in] Points to the wide-character string to be converted.
cchWideChar
[in] Specifies the number of wide characters in the string pointed to by the lpWideCharStr parameter. If this value is -1, the string is assumed to be null-terminated and the length is calculated automatically. The length will include the null-terminator.

Note that if cchWideChar is zero the function fails.

lpMultiByteStr
[out] Points to the buffer to receive the translated string.
cbMultiByte
[in] Specifies the size, in bytes, of the buffer pointed to by the lpMultiByteStr parameter. If this value is zero, the function returns the number of bytes required for the buffer. (In this case, the lpMultiByteStr buffer is not used.)
lpDefaultChar
[in] Points to the character used if a wide character cannot be represented in the specified code page. If this parameter is NULL, a system default value is used. To obtain the system default character which is used if a wide character cannot be represented in the specified code page, use the GetCPInfo or GetCPInfoEx function. The function is faster when both lpDefaultChar and lpUsedDefaultChar are NULL.

For the code pages mentioned in dwFlags, lpDefaultChar must be NULL, otherwise the function fails with ERROR_INVALID_PARAMETER.

lpUsedDefaultChar
[in] Points to a flag that indicates whether a default character was used. The flag is set to TRUE if one or more wide characters in the source string cannot be represented in the specified code page. Otherwise, the flag is set to FALSE. This parameter may be NULL. The function is faster when both lpDefaultChar and lpUsedDefaultChar are NULL.

For the code pages mentioned in dwFlags, lpUsedDefaultChar must be NULL, otherwise the function fails with ERROR_INVALID_PARAMETER.

int MultiByteToWideChar(
UINT CodePage,         // code page
  DWORD dwFlags,         // character-type options
  LPCSTR lpMultiByteStr, // string to map
  int cbMultiByte,       // number of bytes in string
  LPWSTR lpWideCharStr,  // wide-character buffer
  int cchWideChar        // size of buffer
);

 

Parameters
CodePage
[in] Specifies the code page to be used to perform the conversion. This parameter can be given the value of any code page that is installed or available in the system. You can also specify one of the values shown in the following table.
ValueMeaning
CP_ACPANSI code page
CP_MACCPMacintosh code page
CP_OEMCPOEM code page
CP_SYMBOLWindows 2000/XP: Symbol code page (42)
CP_THREAD_ACPWindows 2000/XP: The current thread's ANSI code page
CP_UTF7Windows 98/Me, Windows NT 4.0 and later: Translate using UTF-7
CP_UTF8Windows 98/Me, Windows NT 4.0 and later: Translate using UTF-8.

Windows 95: Under the , MultiByteToWideChar also supports CP_UTF7 and CP_UTF8.

dwFlags
[in] Indicates whether to translate to precomposed or composite-wide characters (if a composite form exists), whether to use glyph characters in place of control characters, and how to deal with invalid characters. You can specify a combination of the following flag constants.
ValueMeaning
MB_PRECOMPOSEDAlways use precomposed charactersthat is, characters in which a base character and a nonspacing character have a single character value. This is the default translation option. Cannot be used with MB_COMPOSITE.
MB_COMPOSITEAlways use composite charactersthat is, characters in which a base character and a nonspacing character have different character values. Cannot be used with MB_PRECOMPOSED.
MB_ERR_INVALID_CHARSIf the function encounters an invalid input character, it fails and GetLastError returns ERROR_NO_UNICODE_TRANSLATION.
MB_USEGLYPHCHARSUse glyph characters instead of control characters.

A composite character consists of a base character and a nonspacing character, each having different character values. A precomposed character has a single character value for a base/nonspacing character combination. In the character , the e is the base character and the accent grave mark is the nonspacing character.

The function's default behavior is to translate to the precomposed form. If a precomposed form does not exist, the function attempts to translate to a composite form.

The flags MB_PRECOMPOSED and MB_COMPOSITE are mutually exclusive. The MB_USEGLYPHCHARS flag and the MB_ERR_INVALID_CHARS can be set regardless of the state of the other flags.

For the code pages in the following table, dwFlags must be zero, otherwise the function fails with ERROR_INVALID_FLAGS.

50220

50221

50222

50225

50227

50229

52936

54936

57002 through 57011

65000 (UTF7)

65001 (UTF8)

42 (Symbol)


Windows XP and later: MB_ERR_INVALID_CHARS is the only dwFlags value supported by Code page 65001 (UTF-8).

lpMultiByteStr
[in] Points to the character string to be converted.
cbMultiByte
[in] Specifies the size in bytes of the string pointed to by the lpMultiByteStr parameter, or it can be -1 if the string is null terminated. Note that if cbMultiByte is 0, the function fails.

If this parameter is -1, the function processes the entire input string including the null terminator. The resulting wide character string therefore has a null terminator, and the returned length includes the null terminator.

If this parameter is a positive integer, the function processes exactly the specified number of bytes. If the given length does not include a null terminator then the resulting wide character string will not be null terminated, and the returned length does not include a null terminator.

lpWideCharStr
[out] Points to a buffer that receives the translated string.
cchWideChar
[in] Specifies the size, in wide characters, of the buffer pointed to by the lpWideCharStr parameter. If this value is zero, the function returns the required buffer size, in wide characters, and makes no use of the lpWideCharStr buffer.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值