Help requested -- importing stuff from a .COM DLL into python


J

John D Salt

I wonder if some kind soul can help me in my struggle with DLLs?

I am trying -- not because I want to, but because I have been told to --
to import things from an API that exists as a bunch of .COM DLLs.

I had originally hoped to get them into a Python 2.4 program by a simple
import statement. This does not appear to work, so I secured a copy of
win32com, and have proven that it works to the extent of opening a M$
Word application.

The same approach with the DLLS I actually need to use consistently fails
with the message "Invalid class string" (full traceback included below, I
doubt that it helps). After a couple of afternoons of vigorous easter-
egging, I have not hit upon a valid class string, and my childish
assumption that it would be one of the names listed in the API
ocumentation is obviously wrong. Staring at the DLL contents with
PEBrowse tells me nothing useful.

Does anyone with experience of getting .COM stuff from DLLs know where I
am going wrong?

(Alternatively, can anyone who has got Python to use the MooD API tell me
how?)

I have no experience of .COM up to this point, and am hoping to keep it
that way once this nonsense is done with.

Thanks for any assistance, and all the best,

John.

- - - - - - - - cut here - - - - - - - -

Traceback (most recent call last):
File "D:\Program Files\MooD\2006\MooDAPI\APIstrangler0_1.py", line 470,
in ?
thing = win32com.client.Dispatch("MooDAPI.Object.Info") # Fails,
"Invalid class string
File "D:\Python24\Lib\site-packages\win32com\client\__init__.py", line
95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName
(dispatch,userName,clsctx)
File "D:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
98, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "D:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
78, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
pythoncom.IID_IDispatch)
com_error: (-2147221005, 'Invalid class string', None, None)
 
Ad

Advertisements

L

Larry Bates

John said:
I wonder if some kind soul can help me in my struggle with DLLs?

I am trying -- not because I want to, but because I have been told to --
to import things from an API that exists as a bunch of .COM DLLs.

I had originally hoped to get them into a Python 2.4 program by a simple
import statement. This does not appear to work, so I secured a copy of
win32com, and have proven that it works to the extent of opening a M$
Word application.

The same approach with the DLLS I actually need to use consistently fails
with the message "Invalid class string" (full traceback included below, I
doubt that it helps). After a couple of afternoons of vigorous easter-
egging, I have not hit upon a valid class string, and my childish
assumption that it would be one of the names listed in the API
ocumentation is obviously wrong. Staring at the DLL contents with
PEBrowse tells me nothing useful.

Does anyone with experience of getting .COM stuff from DLLs know where I
am going wrong?

(Alternatively, can anyone who has got Python to use the MooD API tell me
how?)

I have no experience of .COM up to this point, and am hoping to keep it
that way once this nonsense is done with.

Thanks for any assistance, and all the best,

John.

- - - - - - - - cut here - - - - - - - -

Traceback (most recent call last):
File "D:\Program Files\MooD\2006\MooDAPI\APIstrangler0_1.py", line 470,
in ?
thing = win32com.client.Dispatch("MooDAPI.Object.Info") # Fails,
"Invalid class string
File "D:\Python24\Lib\site-packages\win32com\client\__init__.py", line
95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName
(dispatch,userName,clsctx)
File "D:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
98, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "D:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
78, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
pythoncom.IID_IDispatch)
com_error: (-2147221005, 'Invalid class string', None, None)

Not exactly sure I understand what you need. I call functions that
are stored in Windows .DLLs by using either dynawin.calldll (older
method) or ctypes (newer method). I never thought of them as COM, but
rather compiled C functions stored in .DLL libraries. Maybe you can
call via COM, but I just haven't ever done that. You should be able
to use ctypes to interface to them. The "tricky" part is passing
data back and forth. Building the proper data structures in Python
can take some work.

You should take a look at ctypes from:

http://sourceforge.net/project/showfiles.php?group_id=71702

COM sample is here:

http://starship.python.net/crew/theller/ctypes/sum_sample.html


HTH,
Larry Bates
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top