IPCTrace - An inter-process tracer

Environment: Windows 2000 SP2, VC6 SP5 but will work on all versions

General

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:

void CAnyClass::AnyFunc(...)
{
  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...

If you need help with this or have suggestions how to improve it or state bugs feel free to drop me an email. Updated versions may be found at www.nitrobit.com or www.codecommunity.com.

Downloads

Download demo project - 40 Kb


Comments

  • nice work, but having a problem

    Posted by Legacy on 02/01/2003 12:00am

    Originally posted by: Shehzad Ashraf chaudhary


    I have poblem using hooks. when dll sends messages to application dead lock creates.what I should use to avoid this problem. Tell me how can I use wm_copydata

    Reply
  • The Demo can't go in the first time

    Posted by Legacy on 03/23/2002 12:00am

    Originally posted by: ZhonghuaYi

    When the programe try to read the register table, An exception is thrown out.

    Reply
  • The Demo can't go

    Posted by Legacy on 03/21/2002 12:00am

    Originally posted by: Patrick

    I trace the code and find that the register key "Software\Nitrobit\IPCTtace" is needed.
    Is any other stuff I lost?

    Reply
  • Good work

    Posted by Legacy on 03/20/2002 12:00am

    Originally posted by: masterz

    Yes, DebugView+OutputDebugString is great, but DebugView is only provided as executable, can we ensure it would be updated for future OS?

    Reply
  • OutputDebugString + DebugView

    Posted by Legacy on 03/19/2002 12:00am

    Originally posted by: Alexey Yakovlev

    http://www.sysinternals.com/ntw2k/freeware/debugview.shtml

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • On-demand Event Event Date: July 22, 2014 In this WhatWorks analysis, John Pescatore examines a use case where end users had local administrative rights on their PCs and it had gotten out of hand for this Fortune 500 Energy and Utilities company. The compelling event that prompted the company to reexamine this situation was the migration to Windows 7. In Windows XP, a custom tool that allowed users one of three levels of administrative rights to their workstations would need to be replaced during the Windows …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds