分类 - Accelerated C++

2020-08-05 20:10:44    712    0    0

本文中,企图通过对一段代码实例的 Debug 过程,介绍 Windows 编程中的常见字符编码问题的解决办法。

0x02 问题代码

  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include <stdio.h>
  4. #define INFO_BUFFER_SIZE 32767
  5. void printError(TCHAR* msg);
  6. void main()
  7. {
  8. TCHAR infoBuf[INFO_BUFFER_SIZE];
  9. DWORD bufCharCount = INFO_BUFFER_SIZE;
  10. // Get and display the system directory.
  11. if (!GetSystemDirectory(infoBuf, INFO_BUFFER_SIZE))
  12. printError(TEXT("GetSystemDirectory"));
  13. _tprintf(TEXT("\nSystem Directory: %s"), infoBuf);
  14. }
  15. void printError(TCHAR* msg)
  16. {
  17. DWORD eNum;
  18. TCHAR sysMsg[256];
  19. TCHAR* p;
  20. eNum = GetLastError();
  21. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
  22. FORMAT_MESSAGE_IGNORE_INSERTS,
  23. NULL, eNum,
  24. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  25. sysMsg, 256, NULL);
  26. // Trim the end of the line and terminate it with a null
  27. p = sysMsg;
  28. while ((*p > 31) || (*p == 9
2020-04-19 18:10:15    572    0    0
2020-04-19 08:44:03    415    0    0

C++    2020-04-16 14:08:06    566    0    0
C++    2020-04-15 17:38:53    514    0    0

 
C++    2020-04-15 12:27:18    494    0    0


C++    2020-04-13 19:22:59    492    0    0
C++    2020-04-09 14:09:10    347    0    0

C++    2020-04-02 17:46:09    458    0    0

C++    2020-04-01 18:38:45    433    0    0