Software Hints and Tips
We will cover hints and tips for the various Windows operating systems, as we find items that we think have been undiscovered or ignored by trade publications and other websites.
Windows XP
Anyone that has used Windows XP (and Whistler before it) will have noticed that when an application crashes a dialog box is displayed offering to send data to Microsoft. Thats a great idea when the program that crashed is a Microsoft program. But when the program that crashed is written by you, you don't really want customers sending data about your program's crash to Microsoft. The dialog that is displayed is shown below.
One way to prevent this is to install your own exception handlers to catch any crash that happens. This is fine as far as it goes. You need to do this for each thread in your application, and you need to ensure that the exception handlers are put in the correct place.
A much easier way to deal with this, is to use the new API provided by Microsoft to manage this feature. The API is one function call, which informs the operating system not to display the send data dialog if an application with the specified name crashes. The dialog that is displayed is shown below.
The API is:
BOOL AddERExcludedApplication(LPCTSTR szApplicationName);
When the application name is the name of the application, including file extension and excluding any path information. This function is available in ANSI and UNICODE variants on Windows XP and Windows .Net Server. The required header file is ErrorRep.h. The required import library is FaultRep.lib. You need to define _WIN32_WINNT=0x0500 to use the appropriate parts of Winbase.h (in the latest Platform SDK).
Here is some sample code that will work on any Windows NT4.0, Windows 2000, Windows XP machine is shown below. The application name for this sample is testER.exe.
// Expect this code to fail on any operating system prior to Windows XP
// Hence take no error handling action if it fails
typedef BOOL (__stdcall *AddERExcludedApplicationW_func)(LPCWSTR szApplicationName);
HMODULE hModule;
hModule = LoadLibrary(_T("faultrep.dll"));
if (hModule != NULL)
{
AddERExcludedApplicationW_func addExFunc;
addExFunc = (AddERExcludedApplicationW_func)GetProcAddress(hModule, "AddERExcludedApplicationW");
if (addExFunc != NULL)
{
// note that because we chose the UNICODE (W suffix) version of the API, we must
// force UNICODE characters using L (not _T("") which can also do ANSI)
(addExFunc)(L"testER.exe");
}
FreeLibrary(hModule);
}
Last Updated 7 February, 2008.

