win32com - .ocx won't Dispatch...

R

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,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
 
M

Markus Wankus

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.
 
R

Ray Schumacher

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.<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'><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'>.... 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).... 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)
 
M

Mark Hammond

Ray said:
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)"

My guess is that your OCX is a true OCX, and therefore needs a full GUI
environment. Pythonwin can host these - see the
pythonwin\pywin\demos\ocx directory, and modify one of these to suit.
wxPython can also apparently host OCX controls in a similar way, but I
have no details.

Mark.
 
R

Ray Schumacher

My guess is that your OCX is a true OCX, and therefore needs a full GUI
environment. Pythonwin can host these - see the pythonwin\pywin\demos\ocx
directory, and modify one of these to suit. wxPython can also apparently
host OCX controls in a similar way, but I have no details.

Thank you Mark, I'll look into it next week, for now, I got the DLL drivers
to work with ctypes.

I'll post examples soon.

Cheers,

Ray
 
M

Matt Gerrans

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).
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top