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



John D Salt wrote:
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
.



Relevant Pages

  • Re: Program fails to start using WinInet.dll via type library.
    ... I've only used wininet api using declares, ... One mechanism is to put the names of the DLLs you ... > during your program's execution, and then use GetProcOfAddressto obtain ...
    (microsoft.public.vb.winapi)
  • Re: How can I create a 97 Workgroup? Engine Type=4 Jet OLEDB:Create System Database=True
    ... VB doesn't help here - without a defined API to work from it's ... >> pretty hard to figure out how to use the dlls. ... the Jet dlls you have to worry about. ... company I work for is a book retailer that has close ties to Microsoft Press ...
    (microsoft.public.data.ado)
  • Help requested -- importing stuff from a .COM DLL into python
    ... I wonder if some kind soul can help me in my struggle with DLLs? ... to import things from an API that exists as a bunch of .COM DLLs. ... with the message "Invalid class string" (full traceback included below, ... IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, ...
    (comp.lang.python)
  • RE: replace a COM Objects dll while server is running?
    ... Thanks Nathan, that's a help. ... DLLs Not Unloaded After Calling CoFreeUnusedLibraries ... > Basically, when it is called, this API will free any COM DLLs that are no ...
    (microsoft.public.inetserver.asp.components)
  • Re: Wrapping C API
    ... I've tried using SWIG but am not getting well in windows ... rather easy to load C DLLs and call functions therein. ...
    (comp.lang.python)