can't access com object - why doesn't this work?
christian
christian.schmutzer at gmx.net
Tue Sep 3 07:45:37 EDT 2002
Hi
I ran into a strange problem when accesing the com interface of VC7
using python.
(I am using python and makepy to access the com interface of VC7.)
------------------------------------------
my python code looks as follows:
------------------------------------------
...
DTE = win32com.client.Dispatch('VisualStudio.DTE')
cfgs = DTE.Solution.Projects.Item(1).ConfigurationManager.Platform("Win32")
cfg = cfgs.Item(1)
print cfg
props = cfg.Properties
...
-----------------------------
Basically I retrieve a configuration object from the configuration
manager and then try to access a member function. But the
configuration object always seems to be broken.
When I execute the script, the print still works fine:
output: "<win32com.gen_py.Microsoft Development Environment
7.0.Configuration>"
but accessing the python-property "Properties" causes this error:
Traceback (most recent call last):
[...]
File "C:\PROGRA~1\python\lib\site-packages\win32com\client\__init__.py",
line 355, in __getattr__
return apply(self._ApplyTypes_, args)
File "C:\PROGRA~1\python\lib\site-packages\win32com\client\__init__.py",
line 349, in _ApplyTypes_
return self._get_good_object_(apply(self._oleobj_.InvokeTypes,
(dispid, 0, wFlags, retType, argTypes) + args), user, resultCLSID)
pywintypes.com_error: (-2147352567, 'Exception occured.', (0, None,
None, None, 0, -2147467259), None)
But I really don't understand, why this is illegal. I have researched
the com interface, its relations and internal structures in the
documentation and this should be valid.
I looked at what makepy generated, and that also says that this call
should be possible:
class ConfigurationManager(DispatchBaseClass):
[...]
# Result is of type Configurations
def Platform(self, Name=defaultNamedNotOptArg):
"""Returns a collection of ConfigurationAssignment object for the
specified platform."""
ret = self._oleobj_.InvokeTypes(0x8, LCID, 1, (9, 0), ((8,
0),),Name)
if ret is not None: ret = win32com.client.Dispatch(ret, 'Platform',
'{B6B4C8D6-4D27-43B9-B45C-52BD16B6BA38}', UnicodeToString=0)
return ret
...
class Configurations(DispatchBaseClass):
"""A collection of Configuration objects."""
CLSID = pythoncom.MakeIID('{B6B4C8D6-4D27-43B9-B45C-52BD16B6BA38}')
# Result is of type Configuration
def Item(self, index=defaultNamedNotOptArg):
"""Returns an indexed member of a collection."""
ret = self._oleobj_.InvokeTypes(0x0, LCID, 1, (9, 0), ((12,
1),),index)
if ret is not None: ret = win32com.client.Dispatch(ret, 'Item',
'{90813589-FE21-4AA4-A2E5-053FD274E980}', UnicodeToString=0)
return ret
...
class Configuration(DispatchBaseClass):
[...]
_prop_map_get_ = {
[...]
# Method 'Properties' returns object of type 'Properties'
"Properties": (7, 2, (9, 0), (), "Properties",
'{4CC8CCF5-A926-4646-B17F-B4940CAED472}'),
"Type": (5, 2, (3, 0), (), "Type", None),
So for all I can see, this should work.
So I have also tried out a VB script to retrieve the information, and
it works just fine, so the com objects seem to be valid after all.
-------------------------------------
The VB script looks like this:
-------------------------------------
Dim cfgs As Configurations
Dim cfg As Configuration
Dim props As Properties
cfgs = DTE.Solution.Projects.Item(1).ConfigurationManager.Platform("Win32")
cfg = cfgs.Item(1)
props = cfg.Properties
--------------------------------------
This script works just fine. As you can see, apart from some minor
sytactical things, the script is identical.
I really don't get why this doesn't work in python. So what am I doing
wrong? Am I using python the wrong way, or could this be a python-com
problem?
Has anybody encountered a similar problem?
Thanks,
Christian
More information about the Python-list
mailing list