By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,302 Members | 1,788 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,302 IT Pros & Developers. It's quick & easy.

win32com - .ocx won't Dispatch...

P: n/a
RJ
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,userN ame,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
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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 <ra**@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,userN ame,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
Jul 18 '05 #2

P: n/a
At 12:12 PM 1/29/2004, Markus Wankus wrote:
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.


Thanks Markus,

The lines are from CoClassBaseClass:
....
# This CoClass is known by the name 'EDREUTLX.EDREUtlXCtrl.1'
class EDREUtlX(CoClassBaseClass): # A CoClass
....
That would be a helpful bit for the docs!

So, the util class Dispatches, but all calls (properties and functions) give 'Catastrophic failure'
Is this really some sort of types problem with this OCX?
"pywintypes.com_error: (-2147418113, 'Catastrophic failure', None, None)"

Thanks for the help,
Ray

Test run below, kitchen sink included:

C:\projects\CV-Mini>python
Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
from win32com.client import *
util = gencache._GetModule('8AA34F82-95C9-11D3-8EB6-00C0DF2247CAx0x3x5')
gencache.GetGeneratedFileName('8AA34F82-95C9-11D3-8EB6-00C0DF2247CA',0,3,5) 'AA34F82-95C9-11D3-8EB6-00C0DF2247Cx0x3x5' gencache.MakeModuleForTypelib('8AA34F82-95C9-11D3-8EB6-00C0DF2247CAx0x3x5',0 ,3,5) gencache.GetModuleForCLSID('8AA34F82-95C9-11D3-8EB6-00C0DF2247CA')
gencache.GetClassForCLSID('8AA34F82-95C9-11D3-8EB6-00C0DF2247CA')
gencache.GetModuleForProgID('EDREUTLX.EDREUtlXCtrl .1') <module 'win32com.gen_py.8AA34F82-95C9-11D3-8EB6-00C0DF2247CAx0x3x5' from 'C:\Py
thon23\lib\site-packages\win32com\gen_py\8AA34F82-95C9-11D3-8EB6-00C0DF2247CAx0x
3x5.pyc'> gencache.EnsureModule('{8AA34F82-95C9-11D3-8EB6-00C0DF2247CA}',0,3,5) <module 'win32com.gen_py.8AA34F82-95C9-11D3-8EB6-00C0DF2247CAx0x3x5' from 'C:\Py
thon23\lib\site-packages\win32com\gen_py\8AA34F82-95C9-11D3-8EB6-00C0DF2247CAx0x
3x5.pyc'> gencache.EnsureModule('EDREUTLX.EDREUtlXCtrl.1',0, 3,5)
util = Dispatch("EDREUTLX.EDREUtlXCtrl.1")
util <win32com.gen_py.EDRE Utility Control._DEDREUtlX instance at 0x11224368> gencache.EnsureDispatch(util) <win32com.gen_py.EDRE Utility Control._DEDREUtlX instance at 0x11224728>
util = Dispatch("EDREUTLX.EDREUtlXCtrl.1")
util <win32com.gen_py.EDRE Utility Control._DEDREUtlX instance at 0x11224288> # pop-up, no args .... util.AboutBox()
Traceback (most recent call last):
File "<stdin>", line 2, in ?
File "C:\Python23\lib\site-packages\win32com\gen_py\8AA34F82-95C9-11D3-8EB6-00
C0DF2247CAx0x3x5.py", line 34, in AboutBox
return self._oleobj_.InvokeTypes(-552, LCID, 1, (24, 0), (),)
pywintypes.com_error: (-2147418113, 'Catastrophic failure', None, None) # a property .... util.Version
Traceback (most recent call last):
File "<stdin>", line 2, in ?
File "C:\Python23\lib\site-packages\win32com\client\__init__.py", line 451, in
__getattr__
return self._ApplyTypes_(*args)
File "C:\Python23\lib\site-packages\win32com\client\__init__.py", line 445, in
_ApplyTypes_
return self._get_good_object_(self._oleobj_.InvokeTypes(* ((dispid, 0, wFlags
, retType, argTypes) + args)), user, resultCLSID)
pywintypes.com_error: (-2147418113, 'Catastrophic failure', None, None)


Jul 18 '05 #3

P: n/a
Additionally, you might test with other tools like JScript (or VBScript) a
little ATL program in C++, Microsoft's ActiveX Control Test Container, or
C#. If it needs a window, the JScript/VBScript/ATL will probably fail
similarly. In C#, it is pretty easy to put it an ActiveX control on a
form, or create it independently so you could easily test whether that's the
problem.

By the way, it sounds like maybe you really wanted to create a COM
automation server instead of an ActiveX control (if you don't expect or
require it to be on a window or form).
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.