Debugging COM

Debugging a COM (or OLE, or ActiveX) client is simple-just run the program with your debugger. Servers pose more of a problem since you don't execute them directly. There are several possible solutions you can use with Visual C++.

If your server resides in an EXE file, you have two options. The first is to run the server under the debugger. If the server is a single-use server, you'll need to include /Embedding in the command line. Place any breakpoints you want to examine. Then start the client and create an object. The debugger should trigger a breakpoint at the appropriate place.

Another trick you can use is to modify the server's registry entry so that the LocalProc32 entry is the debugger EXE combined with the command line arguments required to start the server. Then ActiveX will start the debugger. If you use this method, you must make sure the server registers its class factory before the time out expires.

Debugging DLLs is even easier. Just start with the DLL visible in the compiler's IDE. Select Build Settings from the menu and click on the Debug tab. Fill in the name of the client you want to run in the field labeled Executable for debug session. When you attempt to run, you may see a warning that the client doesn't have debugging information. That's no problem.

One common HRESULT you'll see when working with DLLs is 0x800401F9. This result usually means OLE couldn't find your DLLGetClassObject or DLLCanUnloadNowfunctions. Perhaps they are not exported, or the names don't match exactly.

Look for more information on ActiveX Servers in my book Developing ActiveX Web Controls from the Coriolis Group!