WIN32错误处理

以下内容摘自:
http://baike.baidu.com/view/8552073.htm?fr=aladdin

For example:

 1 void TestErrorInfo(void)
 2 {
 3 //进行出错。
 4 if (!CreateDirectory(_T("c:\\"),0))
 5 {
 6 TCHAR szBuf[128];
 7 LPVOID lpMsgBuf;
 8 DWORD dw = GetLastError();
 9 FormatMessage [1] (
10 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
11 NULL,
12 dw,
13 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
14 (LPTSTR) &lpMsgBuf,
15 0, NULL );
16 wsprintf(szBuf,
17 _T("%s 出错信息 (出错码=%d): %s"),
18 _T("CreateDirectory"), dw, lpMsgBuf);
19 LocalFree(lpMsgBuf);
20 //输出提示。
21 OutputDebugString(szBuf);
22 }
23 }

3 api:

GetLastError(),

FormatMessage(),

LocalFree();

posted on 2014-06-30 07:39  aoun  阅读(246)  评论(0编辑  收藏  举报