Also talk about UTF-8 conversion to Unicode method

xiaoxiao2021-03-06  19

A few days ago, it is necessary to do transformation of UTF-8 and GB, mainly because there is a need to use this mode between communication. When he uses C # developed programs to communicate with my VC , it is found that the data he spread to me is UTF-8 type. Therefore, in 9CBS, the transition method of UTF-8 and Unicode is found, and the articles that are found to find are more complicated, so they are started to find in the MSDN. Finally, according to the information found, the following code is written for UTF-8 and Unicode transformation.

BSTR UTF2GB (LPCSTR LP, INT NLEN) {bstr str = NULL; INT NCONVERTEDLEN = MultibytetowideChar (CP_UTF8, 0, LP, NLEN, NULL, NULL); // Bug Fix # 1 (from Q241857): Only Subtract 1 from // The length if the source data is nul-terminated if (nlen == -1) nconvertedlen -; str = :: sysallocstringlen (null, nconvertedlen); if (str! = null) {MultibyTetowideChar (CP_UTF8, 0, LP, NLEN , str, nconvertedlen;} Return Str;}

转载请注明原文地址:https://www.9cbs.com/read-43740.html

New Post(0)