Macro For Stepping Into #import Wrapped COM Methods | CodeGuru

Macro For Stepping Into #import Wrapped COM Methods

When using #import to create wrapper classes for your own C++ COM objects, debugging and stepping into the COM methods can be tedious because you have to first step into the wrapper class and then COM object wrappers for many of the method’s paramenters (e.g. _bstr_t and _variant_t), before you finally get to the raw […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 17, 2000
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

When using #import to create wrapper classes for your own C++ COM objects,
debugging and stepping into the COM methods can be tedious because you have
to first step into the wrapper class and then COM object wrappers for many
of the method’s paramenters (e.g. _bstr_t and _variant_t), before you
finally get to the raw method.

To solve this I have written the macro StepInComFunc to do all the stepping
in and out automatically for you, effectively stepping you directly into
the source code for the method being called. Obviously the COM object will
have to have been built with debug information. I find it useful to map
this macro to the shortcut key ALT+F11.

Sub StepInComFunc()
'DESCRIPTION: A description was not provided.

 Application.Debugger.StepInto

 Dim nMaxParams, nCount
 nCount = 0
 nMaxParams = 20

 Do While ((ActiveDocument.Name = "COMUTIL.H"
 Or ActiveDocument.Name = "ATLBASE.H")
 And nCount < nMaxParams)

  Application.Debugger.StepOut
  Application.Debugger.StepInto
  nCount = nCount + 1
 Loop

 if (ActiveDocument.Name = "COMIP.H") then
  Application.Debugger.StepOut
  Application.Debugger.StepInto
 End If

 if (ActiveDocument.Name = "COMIP.H") then
  Application.Debugger.StepOut
  Application.Debugger.StepInto
 End If

 if (InStr(ActiveDocument.Name, ".tli") > 0) then
  Application.Debugger.StepOver
  Application.Debugger.StepInto
 End If

 nCount = 0
 Do While ((ActiveDocument.Name = "COMUTIL.H"
 Or ActiveDocument.Name = "ATLBASE.H")
 And nCount < nMaxParams)
  Application.Debugger.StepOut
  Application.Debugger.StepInto
  nCount = nCount + 1
 Loop

End Sub
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.