// Get the error code
DWORD dwError = GetDlgItemInt(IDC_EDIT1);
HLOCAL hlocal = NULL; // Buffer that gets the error message string
// Use the default system locale since we look for Windows messages.
// Note: this MAKELANGID combination has 0 as value
DWORD systemLocale = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
// Get the error code's textual description
BOOL fOk = FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_ALLOCATE_BUFFER,
NULL, dwError, systemLocale,
(PTSTR) &hlocal, 0, NULL);
SetDlgItemText(IDC_TEXTOUT,(PTSTR) LocalLock(hlocal));FormatMessage 错误消息
最新推荐文章于 2025-08-20 11:48:45 发布
本文介绍了一种在Windows系统中通过使用API函数GetDlgItemInt和FormatMessage获取用户界面上显示的错误代码,并将其转换为对应的错误消息字符串的方法。此过程涉及获取错误代码、设置缓冲区以接收错误消息字符串及调用FormatMessage函数。
1073

被折叠的 条评论
为什么被折叠?



