关于 用WideCharToMultiBytes处理wchar_t出现的问题!!急
wchar_t *wname;
wname = new wchar_t[31];
wcscpy(wname,pDoc-> astruELCalcModelSubSystemPara.GetAt(index).name);//pDoc-> astruELCalcModelSubSystemPara.GetAt(index).name是一个wchar_t数组
dwNum = WideCharToMultiByte(CP_ACP, NULL, wname, -1, NULL, 0, NULL, NULL);
psText = new char[dwNum];
if (!psText)
{
delete []psText;
}
WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, wname, -1, psText, dwNum, NULL, NULL);
m_ctrlPloot.InsertItem(psText,patchNode,TVI_LAST);
出现的问题就是我这样处理后,树中的内容显示出的是一些问号,麻烦大家帮忙看一看
[解决办法]
WC_COMPOSITECHECK and related flags
As discussed in the Unicode Normalization topic, Unicode allows multiple representations of the same string (interpreted linguistically). For example, Capital A with dieresis (umlaut) can be represented either precomposed as a single Unicode code point "Ä " (U+00C4) or decomposed as the combination of Capital A and the combining dieresis character ( "A " + "¨ ", that is U+0041 U+0308). However, most code pages provide only composed characters.
The WC_COMPOSITECHECK flag causes the WideCharToMultiByte function to test for decomposed Unicode characters and attempt to compose them before converting them to the requested code page. This flag is only available for conversion to single byte (SBCS) or double byte (DBCS) code pages (code pages < 50000, excluding code page 42). If your application needs to convert decomposed Unicode data to single byte or double byte code pages, this flag might be useful. However, not all characters can be converted this way and it is more reliable to save and store such data as Unicode.
When an application is using WC_COMPOSITECHECK, some character combinations might remain incomplete or might have additional nonspacing characters left over. For example, A + ¨ + ¨ combines to Ä + ¨. Using the WC_DISCARDNS flag causes the function to discard additional nonspacing characters. Using the WC_DEFAULTCHAR flag causes the function to use the default replacement character (typically "? ") instead. Using the WC_SEPCHARS flag causes the function to attempt to convert each additional nonspacing character to the target code page. Usually this flag also causes the use of the replacement character ( "? "). However, for code page 1258 (Vietnamese) and 20269, nonspacing characters exist and can be used. The conversions for these code pages are not perfect. Some combinations do not convert correctly to code page 1258, and WC_COMPOSITECHECK corrupts data in code page 20269. As mentioned earlier, it is more reliable to design your application to save and store such data as Unicode.
Windows normally represents Unicode strings with precomposed data, making the use of the WC_COMPOSITECHECK flag unnecessary. The less common applications that create decomposed data cannot accurately represent many decomposed character combinations in most code pages. Unicode is the preferred way to save and store such data.
出处: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_2bj9.asp