Environment: Windows 2000 SP2, VC6 SP5 but will work on all versions
In the last few month I coded a lot of global hook and out-of-process COM server related stuff. Global hooks are hard to debug because they’re normally called in the context of the debugger process too. You can’t use message boxes, etc. to report some action because this may cause your system to hang permanently under certain circumstances. There are tricks to resolve these problems (MSDN: Q179905), but I figured out problems under Windows 9x/Me. So I wrote my own inter-process tracer.
How it works
I tried to keep this tool as simple and easy to use as possible. I use the WM_COPYDATA for the IPC cause this seemed to be the simplest (and fastest) way to fit my needs.
How to integrate
In order to use this IPC-tracer simply build the IPCTrace project (there are english and german resources included) and launch the application.
You should make a release build because you probably won’t change any code of that project. To trace messages out of your application to the IPCTrace window I provided a macro called IPCTRACE. The definition of this macro can be found in the file IPCTraceMacros.h
#if (defined _DEBUG || defined _IPCRELEASETRACE)
#define IPCTRACE(message) \
HWND hReceiver = ::FindWindow(NULL, _T(“IPCTrace”)); \
if (hReceiver) \
COPYDATASTRUCT cds; \
ZeroMemory(&cds, sizeof(COPYDATASTRUCT)); \
cds.dwData = 0x00031337; \
cds.cbData = _tcslen(message) + sizeof(TCHAR); \
cds.lpData = message; \
::SendMessage(hReceiver, WM_COPYDATA, NULL, (LPARAM) &cds); \
#else // defined _DEBUG || defined _IPCRELEASETRACE
#define IPCTRACE (void(0))
#endif // !_DEBUG
As you can see it is very simple. To use this macro include the IPCTraceMacros.h header and call the macro like this:
IPCTRACE(_T(“Trace this text…”))
An additional feature is that you can enable tracing in your release builds too! As you see in the codesample above you can define _IPCRELEASETRACE at the preprocessor definitions of your release build settings in order to make the macro work. In order to test this I supplied a simple client application called IPCTraceClient which is included in the package too. Try it and you’ll see how it works…