473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Communicating with MSVC++ via COM: how?

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
time.sleep(2)
app.Visible = 1

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

## Load pseudo-workspace for our executable
workSpace = "C:\\tmp\\AllCheckings\\AllCheckings\\Debug\\AllCh eckings.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
bkpts.RemoveAllBreakpoints()
bkpts.AddBreakpointAtLine(86)
---------------------------------------------

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

Traceback (most recent call last):
File "test.py", line 13, in ?
docs.CloseAll()
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 "test.py", line 30, in ?
bkpts.AddBreakpointAtLine(86)
File "H:\Tools\Python\bin\Windows\Python21\win32com\cli ent\dynamic.py", line
151, in __call__
return
self._get_good_object_(apply(self._oleobj_.Invoke, allArgs),self._olerepr_.defaultDispatchName,None)
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.

TIA
--
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

Jul 18 '05 #1
2 1820
Eric Brunel wrote:
This script doesn't work: the call to docs.CloseAll fails with the error:

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


This is because docs.CloseAll is making the call, and returning an int.
This, docs.CloseAll() is attempting to call that int.

It looks very much like you have no makepy support for MSVC built.

Just after the line:
app = win32com.client.Dispatch('MSDev.Application')
Try adding:
app = win32com.client.gencache.EnsureDispatch(app)

That should force makepy, and everything should start working.

Mark

Jul 18 '05 #2
Mark Hammond wrote:
Eric Brunel wrote:
This script doesn't work: the call to docs.CloseAll fails with the error:

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

This is because docs.CloseAll is making the call, and returning an int.
This, docs.CloseAll() is attempting to call that int.


Hi Mark,

Thanks for your answer. We finally figured out this one, but the problem lies a
bit farther in the script:

bkpts.AddBreakpointAtLine(86)

The method AddBreakpointAtLine takes an *optional* parameter which is the line
number on which to put the breakpoint. But bkpts.AddBreakpointAtLine actually
calls the method AddBreakpointAtLine with no parameter, so I just can't figure
out how to call the method *with* a parameter...
It looks very much like you have no makepy support for MSVC built.

Just after the line:
app = win32com.client.Dispatch('MSDev.Application')
Try adding:
app = win32com.client.gencache.EnsureDispatch(app)

That should force makepy, and everything should start working.


I tried what you suggest, but it didn't work: I get the following error:
app = win32com.client.gencache.EnsureDispatch(app)

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "H:\Tools\Python\bin\Windows\Python21\win32com\cli ent\gencache.py", line
423, in EnsureDispatch
disp = win32com.client.Dispatch(prog_id)
File "H:\Tools\Python\bin\Windows\Python21\win32com\cli ent\__init__.py", line
95, in Dispatch
return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo,
UnicodeToString, clsctx)
File "H:\Tools\Python\bin\Windows\Python21\win32com\cli ent\__init__.py", line
26, in __WrapDispatch
typeinfo = dispatch.GetTypeInfo()
File "H:\Tools\Python\bin\Windows\Python21\win32com\cli ent\dynamic.py", line
438, in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: MSDev.Application.GetTypeInfo

Trying to force the generation of the support files via an explicit makepy.py
didn't work either: doing a Dispatch('MsDev.Application') still doesn't get the
right type. Forcing the type by doing Dispatch('MsDev.Application',
resultCLSID="{the-class-id}") seems to work, but apparently, the generated class
knows nothing about the types of its members and simple things as:

app.Visible = 1

fail with a traceback (something like "incorrect type for variable" - sorry for
the imprecision: we have a French Windows, so the message I get is in
French...). Getting an attribute like app.Debugger seems to work, but printing
it says:
<COMObject Debugger>
so the object is a dynamic one, and also knows nothing about its type.

Is there any solution to our problems?

TIA
--
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
0
by: Leor Zolman | last post by:
The Intel C++ version of STLFilt (my STL Error Message Decryptor utility) has now been updated to support Intel C++ 8 (currently in Beta) along with version 7. All three MSVC libraries are...
2
by: Robert Oschler | last post by:
Need help with HEAP CORRUPTION and my MSVC 6 DLL I have a MSVC 6 DLL that I've written. It is used heavily by a Delphi 6 app I've written. For two months everything has been working fine. ...
8
by: Chris Stankevitz | last post by:
I can't tell you how frusterated I and my coworkers are with "MSVC 7.1 .net 2003" (what am I supposed to call this thing anyway?). Compiling and linking take twice as long with "MSVC 7.1 .net...
6
by: Uli | last post by:
Hello, I'm trying to use a DLL (by static linking) which was compiled with Borland C++Builder (BCB) in Visual C++ (Visual-Studio 2003). All functions are declared with the directive 'extern...
23
by: Babak | last post by:
Hi Everyone, I've written a standard C code for a simple finite element analysis in MSVC++ . When I save the file as a cpp file, it compiles and runs perfectly, but when I save it as a c file,...
6
by: ma | last post by:
Hello, Some questions about upgrading to MSVC 2008. 1- I am using MSVC2005, Do you recommend that I upgrade to MSVC 2008 Beta 2? 2- When the MSVC2008 will be officially release? 3- Where...
17
by: fl | last post by:
Hi, I am learning C++ from the following C++ website, which has some very good small examples. For the second Fraction example, which has five files: Main.cpp Fraction.cpp Fraction.h...
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.