Mar 292010
Note to self: It never rains in Oregon, but don’t they warn ya, it pours, man it pours… IOW, keep an umbrella in the car dummy.
Mar 262010
This function is handy for getting and formatting the string that is associated with critical errors. You just pass in the errno returned from a Win32 call. This information is available elsewhere, but I’ve found this encapsulated function to be handy.
CString GetCriticalErrorString(DWORD nError) {
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, nError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL );
CString cs = (LPCTSTR)lpMsgBuf;
LocalFree(lpMsgBuf);
return cs;
}
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, nError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL );
CString cs = (LPCTSTR)lpMsgBuf;
LocalFree(lpMsgBuf);
return cs;
}