Problem with COM and variants

Simon Carter bbbscarter at gmail.com
Tue Apr 21 05:37:20 EDT 2009


Hullo! I'm having a problem interfacing with a proprietary COM library on 
Windows, and I was hoping someone could help. I'm no COM guru, so apologies 
in advance if my terminology gets a little muddled...

I'm accessing the COM library via gencache.EnsureModule. It was all working 
as expected until I needed to access a property of a COM interface that 
returns a variant. So:

    my_object.SomeMethod() # works fine
    val = my_object.RunningProcessInfo #throws a 'The parameter is 
incorrect' com_error
    val = my_object.RunningProcessInfo() #tried that just in case, but it 
also throws a 'The parameter is incorrect' com_error
    val = my_object.get_RunningProcessInfo() #nope, "object has no attribute 
'get_RunningProcessInfo()'"

Looking at the generated interface python file, although RunningProcessInfo 
exists, there is no reference to the PROCESS_INFO structure it is meant to 
return. If I browse the library using the pythonwin COM browser I can see 
that the relevant structure exists, flagged as a 'Record' in the browser, 
although I can't inspect its members.

Thinking that maybe structures are generated on the fly, I tried forcing the 
creation of the given record type:

    val = win32com.client.Record("PROCESS_INFO", my_object) #The structure 
"PROCESS_INFO" is not defined in the module <module win32com.gen_py.####>

As such, from my point of view of almost total ignorance, it seems that my 
problem is being caused by the PROCESS_INFO structure not being 
generated/accessible. More likely, of course, it that I'm being an arse and 
doing it wrong.

Some other notes:
- I've tried similar things using the late binding 'Dispatch' interface, but 
without any luck.
- I've tried the same thing with various other properties that return 
structures, with the same result.
- It may not be related, but I've also had a look at some other libraries, 
such as the "DirectX Transforms Core Type Library", and there are lots of 
structures in there that appear in the COM browser, but don't appear in the 
generated interface file.
- I'm running 32bit python 2.6 and pywin32 build 213, on Vista 64.

Any help much appreciated.

Thanks!

Simon 




More information about the Python-list mailing list