Communicating with MSVC++ via COM: how?

Eric Brunel eric.brunel at
Thu Jan 8 14:09:42 CET 2004

Hi all,

We're trying to communicate with Microsoft Visual C++ 6.0 via COM to make it 
perform a few operations. Our main need is to set a breakpoint on a given line 
in a given file. We ended up with the following script:

import win32com.client
import time

## Get MSVC++ main application
app = win32com.client.Dispatch('MSDev.Application')

## Make the window visible
app.Visible = 1

## Get loaded documents in MSVC++ and close them all
docs = app.Documents

## Load pseudo-workspace for our executable
workSpace = "C:\\tmp\\AllCheckings\\AllCheckings\\Debug\\AllCheckings.exe"
docs.Open(workSpace, 'Auto', 1)

## Open file where we want to put the breakpoint
docs.Open( "C:\\tmp\\AllCheckings\\ccg\\MyFile.c" )

## Get MSVC++ debugger
dbgr = app.Debugger

## Get breakpoint list
bkpts = dbgr.Breakpoints

## Clear all break points, then add the one we want

This script doesn't work: the call to docs.CloseAll fails with the error:

Traceback (most recent call last):
   File "", line 13, in ?
TypeError: object of type 'int' is not callable

which is quite weird, to say the least...

Since we didn't understand what was going on, we finally decided to comment out 
this line and to try again. The script then fails on the last line with the error:

Traceback (most recent call last):
   File "", line 30, in ?
   File "H:\Tools\Python\bin\Windows\Python21\win32com\client\", line 
151, in __call__
pywintypes.com_error: (-2147352573, 'Membre introuvable.', None, None)

The weird thing is that apparently, something is actually called, since a 
breakpoint *is* set, but not on the line we requested. It seems to be set on the 
line where the cursor is in the file opened in MSVC++.

In fact, it seems like just doing docs.CloseAll or bkpts.AddBreakpointAtLine 
(without the ()) does not return the method, but actually calls it.

We tried to use makepy to generate the COM support files for the objects we 
used, but the result were even weirder: the line "app.Visible = 1" crashed, 
saying that the attribute could not be set. Using gencache.EnsureModule didn't 
help: it also crashed because of an attribute MinorVersion missing on a module.

Did we miss something here? We're somewhat rookies wrt COM, but we're quite 
fluent with Python (apparently, this doesn't seem to help a lot...). Did anyone 
succeed in communicating with MSVC++ via COM from Python? Or did anyone see the 
kind of problems we're having here? We're using Python 2.1 with win32all-136.

- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools -

More information about the Python-list mailing list