// ********************************************************************** // // ** This file was downloaded from Jeff Heaton's Source Code Examples ** // // ** www.heat-on.com/source ** // // ********************************************************************** // // Copyright 1999 by Jeff Heaton // ********************************************************************** // // Permission is granted for royaltyfree use in compiled form. No // additional licensing is required. This code may not be distributed // in source form without written premission by Jeff Heaton. Generally // I will grant it. Just ask first. // // Basically I do not care how you distribute this code in compiled form. // But if your going to publish my source code somewhere I'd like to hear // about it first. // ********************************************************************** // // ErrorHandler V1.0 // Written 1/14/1999 by Jeff Heaton // // Associate text with Windows numeric error codes. // // This routine can be included in any project to provide a simple interface // to the GetLastError() API call. This routine will call GetLastError() // and then look up a text description assocated with that error. An // application specific error message can also be included. This makes // it very easy to look up all those numeric Windows error codes right in // your program. #include // Function Name: ErrorHandler // Parameters: // msg - Error message to display // Returns: // Nothing. // Purpose: // This function is used to report errors to the user. // Author // Jeff Heaton void ErrorHandler(char *msg) { LPVOID lpMsgBuf;// The GetLastError error message char *complete;// Used to build complete error message FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); complete = (char*)LocalAlloc( LMEM_FIXED,LocalSize(lpMsgBuf) + 2 + lstrlen(msg) ); lstrcpy(complete,msg); lstrcat(complete,"\r\n"); lstrcat(complete,(char*)lpMsgBuf); MessageBox( NULL, (const char *)complete, "Error", MB_OK|MB_ICONINFORMATION ); LocalFree( lpMsgBuf ); LocalFree( complete ); }