win32com - .ocx won't Dispatch...

Markus Wankus markus_wankus at hotmail.com
Thu Jan 29 21:12:44 CET 2004


Open the gen_py'd file 8AA34F82-95C9-11D3-8EB6-00C0DF2247CAx0x3x5.py, and 
do some searching.  You should be able to find an obvious main class 
related to what you are doing (I'm not sure what the .tlb is), and it will 
say in the comment or docstring that it is a "<foo>.<bar>", or whatever.  
That will be what you need to Dispatch.  The other option is to use the 
OLEView tool tiwth MSVC, and look at your EDRE Utility Control.  It will 
say in there somewhere...

Markus.

On Wed, 28 Jan 2004 19:04:22 -0800, RJ <rays at san.rr.com> wrote:

> Hi,
> I've been going over the Quick Start to Client side COM and Python and 
> many other sources, but cannot find an example that will get my 
> com/ActiveX .ocx USB device driver imported.
>
> The Excel and Word examples run fine.
> win32com.client.Dispatch("Excel.Application") etc., but how does one 
> know the ("<foo>.<bar>") to type in? Excel looks only vaguely like 
> "Excel.Application" in the com browser.
>
> Firstly, I found the ocx from the Python Object Browser.
> I ran makepy.py on EDREUtlX.ocx (USB device driver) which created
> 8AA34F82-95C9-11D3-8EB6-00C0DF2247CAx0x3x5.py
> etc. in gen_py\,
> but, I cannot find a syntax to get Dispatch to accept it...
>
> from win32com.client import Dispatch
> # failed attempts
> Dispatch("EDRE Utility Control") # name in browser
> Dispatch('{8AA34F82-95C9-11D3-8EB6-00C0DF2247CAx0x3x5}')
> Dispatch('{8AA34F82-95C9-11D3-8EB6-00C0DF2247CA}')
> Dispatch("8AA34F82-95C9-11D3-8EB6-00C0DF2247CA")
> Dispatch("8AA34F82-95C9-11D3-8EB6-00C0DF2247CAx0x3x5")
>
> all return:
> Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
>    File "C:\Python23\lib\site-packages\win32com\client\__init__.py", 
> line 95, in Dispatch
>      dispatch, userName = 
> dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
>    File "C:\Python23\lib\site-packages\win32com\client\dynamic.py", line 
> 84, in _GetGoodDispatchAndUserName
>      return (_GetGoodDispatch(IDispatch, clsctx), userName)
>    File "C:\Python23\lib\site-packages\win32com\client\dynamic.py", line 
> 72, in _GetGoodDispatch
>      IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, 
> pythoncom.IID_IDispatch)
> pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
>
> So, what is the required syntax?
>
> Thanks,
> Ray
>
>



-- 
--
Markus



More information about the Python-list mailing list