C++定义自己的错误代码(FormatMessage)
来源:互联网 发布:adams软件简介 编辑:程序博客网 时间:2024/06/06 20:26
The FormatMessage function can be used to obtain error message strings for the system error codes returned by GetLastError, as shown in the following sample code.
LPVOID lpMsgBuf;FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL );// Process any inserts in lpMsgBuf.// ...// Display the string.MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );// Free the buffer.LocalFree( lpMsgBuf );
CSerialPort串口类中自己定义的错误代码程序如下:(Remon Spekreijse写的一个串口类, 地址在: http://codeguru.earthweb.com/network/serialport.shtml)
void CSerialPort::ProcessErrorMessage(char* ErrorText)
{
char *Temp = new char[200];
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
sprintf(Temp, "WARNING: %s Failed with the following error: /n%s/nPort: %d/n", (char*)ErrorText, lpMsgBuf, m_nPortNr);
MessageBox(NULL, Temp, "Application Error", MB_ICONSTOP);
LocalFree(lpMsgBuf);
delete [] Temp;
}
- C++定义自己的错误代码(FormatMessage)
- 定义自己的错误代码
- 定义自己的错误代码
- FormatMessage 格式化 GetLastError 获取的错误代码
- FormatMessage获取错误代码描述
- FormatMessage 格式化 GetLastError 错误代码
- FormatMessage将错误代码转换成对应的字符串
- FormatMessage();错误代码to文本描述
- FormatMessage函数的使用(转)
- 自己编写错误代码的规范
- C++Builder中定义自己的事件
- 定义自己的头文件(C语言)
- FormatMessage的用法
- FormatMessage 的使用
- FormatMessage 的用法
- FormatMessage的用法
- FormatMessage函数的用法
- FormatMessage的用法
- IIS部署说明server2003
- 2011 端午后,杭州支付宝
- 通过SharedPreferences方式存储复杂数据
- 使用mondrian建立立方体
- C++ virtual constructors virtual copy constructors 以及non-memeber functions的行为虚化
- C++定义自己的错误代码(FormatMessage)
- java IO系统详解
- Jboss Seam3 Weld Jpa在J2SE中使用之五[安全框架之一认证]
- WEB 打印 print()
- 对string、stringbuilder、stringbuffer全面解析
- java中IO流的感悟
- IE下CSS属性float:right下移换行或不显示的问题原因及解决
- (UML) 关联 之 多重度
- BW与ECC系统连接设置