金笛工业手机论坛

金笛工业手机论坛 (http://bbs.sendsms.cn/)
-   短信开发资料 (http://bbs.sendsms.cn/cy-ae-eu-ae/)
-   -   UTF8-ANSI.cpp (http://bbs.sendsms.cn/cy-ae-eu-ae/2777.htm)

admin 2012-08-24 17:52

UTF8-ANSI.cpp
 
UTF8-ANSI.cpp

//首先从UTF8转到UNCODE
  1. //再从UNCODE转到ANSI </SPAN>
  2. int ConvUtf8ToAnsi(CString& strSource, CString& strChAnsi) </SPAN>
  3. {
  4. if (strSource.GetLength() <= 0) </SPAN>
  5. return 0; </SPAN>
  6. CString strWChUnicode;
  7. strSource.TrimLeft();
  8. strSource.TrimRight();
  9. strChAnsi.Empty();
  10. int iLenByWChNeed = MultiByteToWideChar(CP_UTF8, 0, </SPAN>
  11. strSource.GetBuffer(0),
  12. strSource.GetLength(), //MultiByteToWideChar </SPAN>
  13. NULL, 0);
  14. int iLenByWchDone = MultiByteToWideChar(CP_UTF8, 0, </SPAN>
  15. strSource.GetBuffer(0),
  16. strSource.GetLength(),
  17. (LPWSTR)strWChUnicode.GetBuffer(iLenByWChNeed * 2), </SPAN>
  18. iLenByWChNeed); //MultiByteToWideChar </SPAN>
  19. strWChUnicode.ReleaseBuffer(iLenByWchDone * 2);
  20. int iLenByChNeed = WideCharToMultiByte(CP_ACP, 0, </SPAN>
  21. (LPCWSTR)strWChUnicode.GetBuffer(0), </SPAN>
  22. iLenByWchDone,
  23. NULL, 0,
  24. NULL, NULL);
  25. int iLenByChDone = WideCharToMultiByte(CP_ACP, 0, </SPAN>
  26. (LPCWSTR)strWChUnicode.GetBuffer(0), </SPAN>
  27. iLenByWchDone,
  28. strChAnsi.GetBuffer(iLenByChNeed),
  29. iLenByChNeed,
  30. NULL, NULL);
  31. strChAnsi.ReleaseBuffer(iLenByChDone);
  32. if (iLenByWChNeed != iLenByWchDone || iLenByChNeed != iLenByChDone) </SPAN>
  33. return 1; </SPAN>
  34. return 0; </SPAN>
  35. }


所有时间均为北京时间。现在的时间是 10:12

Powered by vBulletin® 版本 3.8.3
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.