首页 > 代码库 > MFC ERROR GetLastError
MFC ERROR GetLastError
1 void CStockServerDlg::ErrorExit(LPTSTR lpszFunction) //错误函数 2 { 3 // Retrieve the system error message for the last-error code 4 5 LPVOID lpMsgBuf; 6 LPVOID lpDisplayBuf; 7 DWORD dw = GetLastError(); 8 9 FormatMessage(10 FORMAT_MESSAGE_ALLOCATE_BUFFER | 11 FORMAT_MESSAGE_FROM_SYSTEM |12 FORMAT_MESSAGE_IGNORE_INSERTS,13 NULL,14 dw,15 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),16 (LPTSTR) &lpMsgBuf,17 0, NULL );18 19 // Display the error message and exit the process20 21 lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, 22 (lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR)); 23 StringCchPrintf((LPTSTR)lpDisplayBuf, 24 LocalSize(lpDisplayBuf),25 TEXT("%s failed with error %d: %s"), 26 lpszFunction, dw, lpMsgBuf); 27 ::MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); 28 LocalFree(lpMsgBuf);29 LocalFree(lpDisplayBuf);30 ExitProcess(dw);31 }32 33 //调用它34 CStockServerDlg* pError =new CStockServerDlg();35 pError->ErrorExit(TEXT("Create"));36 delete pError; //避免其成为"野指针"37 pError = NULL;
MFC ERROR GetLastError
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。