Noteamini
Noteamini

Reputation: 13

Python ActiveX automation

I am trying to use ActiveX automation with python to control Audio Precision ATS-2. I am using pywin32 32-bit Windows XP with Python 2.7.

I installed the audio Precision software. Then I used makepy utility which found Audio Precision in the list and created a wrapper for it. Everything is going well until I attempt to call dispatch function abd I am stuck.

from guides I found online,

win32com.client.Dispatch("Excel.Application")

What should I put in the area that says "Excel.Application"?

How can I find this?

When I used OLE/COM Object viewer, I see Audio Precision entries under type library, but I am unsure how does the information in it could help me.

I have attempted few things on my own, but got almost no result. The best result I got was when I entered the CLSID in dispatch function, which I found in the wrapper object makepy created.

win32com.client.Dispatch("{80EC6E76-D94F-48EB-8F4C-05BDD7850BF1}")

which gave me the following error:

    Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\win32com\gen_py\APtest.py", line 5, in <module>
    xlApp = win32com.client.Dispatch("{80EC6E76-D94F-48EB-8F4C-05BDD7850BF1}")
  File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
com_error: (-2147221164, 'Class not registered', None, None)

I have:

How can I fix this?

Upvotes: 0

Views: 7445

Answers (3)

shipof
shipof

Reputation: 11

I had the same issue. I didn't know where to get that, which from what I can gather is the name of the CoClass (which I believe is the wrapper for the dll) created by the makepy program (maybe I'm wrong). After I read the answer by @NotAUser I found it, but when I inspected the file created by the makepy program, and right before the last class, (if more than one are created) I found the following:

from win32com.client import CoClassBaseClass
# This CoClass is known by the name 'ZKFPEngXControl.ZKFPEngX'
class ZKFPEngX(CoClassBaseClass): # A CoClass

So, there, in the same file there was the name I needed to use.

Upvotes: 1

Voltage Spike
Voltage Spike

Reputation: 160

To use the pywin32 module with an activex class you need to generate a wrapper file. To do this locate your makepy.py file in C:\Python27\Lib\site-packages\win32com\client (or your simmilar dir). Then run it, locate the NAME of your activex class then run it. It should generate a wrapper file in the gen_py folder C:\Python27\Lib\site-packages\win32com\gen_py with the CLSID in it. You can then access it like the excel example and the same way you would in other languages.

Upvotes: 1

NotAUser
NotAUser

Reputation: 1456

Possible way to solve this:

  • Identify the Audio Precision ATS-2 dll you want to call. E.g. "C:\path\my.dll"
  • Now go to the registry and look for "C:\path\my.dll". You'll find a few things around but what you really want is an entry in CLSID...\InprocServer32 folder, or something similar
  • There will be a ProgID entry as well, something like "AudioPrecison.ATS2"
  • Now in Python try win32com.client.Dispatch("AudioPrecison.ATS2")

Upvotes: 3

Related Questions