1 voidCstockserverdlg::errorexit (LPTSTR lpszfunction)//Error function2 {3 //Retrieve The system error message for the Last-error code4 5 lpvoid lpMsgBuf;6 lpvoid lpdisplaybuf;7DWORD DW =GetLastError ();8 9 FormatMessage (TenFormat_message_allocate_buffer | OneFormat_message_from_system | A Format_message_ignore_inserts, - NULL, - DW, the makelangid (lang_neutral, Sublang_default), -(LPTSTR) &lpMsgBuf, - 0, NULL); - + //Display the error message and exit the process - +Lpdisplaybuf =(LPVOID) LocalAlloc (Lmem_zeroinit, A(Lstrlen (LPCTSTR) lpmsgbuf) +lstrlen ((LPCTSTR) lpszfunction) + +)*sizeof(TCHAR)); at stringcchprintf (LPTSTR) lpdisplaybuf, - localsize (lpdisplaybuf), -TEXT ("%s failed with error%d:%s"), - lpszfunction, DW, LPMSGBUF); -:: MessageBox (NULL, (LPCTSTR) lpdisplaybuf, TEXT ("Error"), MB_OK); - LocalFree (LPMSGBUF); in LocalFree (LPDISPLAYBUF); - ExitProcess (DW); to } + - //Call it thecstockserverdlg* perror =NewCstockserverdlg (); *Perror->errorexit (TEXT ("Create")); $Delete perror;//avoid it becoming a "wild pointer"Panax Notoginsengperror = NULL;
MFC ERROR GetLastError