Call OCX from python?

J

JustSomeGuy

Hi I have a commercial OCX that I want to use in
my python application. How do I call OCXs from
python?
TIA
 
D

Do Re Mi chel La Si Do

From WxPython, or from PythonWin.

Other way : call, & drive, Internet-Explorer, who call the ocx.

Michel Claveau
 
C

Claudio Grondi

JustSomeGuy said:
Hi I have a commercial OCX that I want to use in
my python application. How do I call OCXs from
python?
TIA

import win32com.client
axOCX =
win32com.client.Dispatch("RegistryEntryForThisOCXin[VersionIndependentProgID
]section")
retVal = axOCX.methodOfThisOCX(param1, param2)
value = axOCX.attributeOfThisOCX

Claudio
 
J

JustSomeGuy

Claudio Grondi said:
JustSomeGuy said:
Hi I have a commercial OCX that I want to use in
my python application. How do I call OCXs from
python?
TIA

import win32com.client
axOCX =
win32com.client.Dispatch("RegistryEntryForThisOCXin[VersionIndependentProgID
]section")
retVal = axOCX.methodOfThisOCX(param1, param2)
value = axOCX.attributeOfThisOCX

Claudio

Thank you Claudio...
Can you explain the RegistryEntryForThisOcxin[VersionIndependentProgID]
I don't know what I should use here..
 
C

Claudio Grondi

JustSomeGuy said:
Claudio Grondi said:
import win32com.client
axOCX =
win32com.client.Dispatch("RegistryEntryForThisOCXin[VersionIndependentProgID
]section")
retVal = axOCX.methodOfThisOCX(param1, param2)
value = axOCX.attributeOfThisOCX

Claudio

Thank you Claudio...
Can you explain the RegistryEntryForThisOcxin[VersionIndependentProgID]
I don't know what I should use here..

An ActiveX component (e.g. an OCX) requires to be registered before it can
be used. Usually this is done when the component is installed. If you know
the file name of the OCX start the registry editor running the command:
regedit ([Start] -> Execute -> regedit). Then search for the file name of
the OCX in the registry. One of the hits should lead you to a registry key
where you find on same hierarchy level the [VersionIndependentProgID] entry.
The name there is what you should use in the win32com.client.Dispatch() as
parameter.
To give an example let's assume you want to use the WSHOM.OCX which is
usually on any Windows system. Looking in the registry for WSHOM.OCX leads
you (probably the second hit) to the key [InProcServer32] in the
{72C24DD5-D70A-438B-8A42-98424B88AFB8} entry. Here you find also the key
[VersionIndependentProgID] with the standard value of WScript.Shell. You
should exactly know the methods and their parameter to be able to use the
OCX, see the code below :

# Raise a Yes/No/Abort dialog box provided by WSHOM.OCX:

import win32com.client
axWshShell = win32com.client.Dispatch("WScript.Shell") # WSHOM.OCX

axWshShell_Popup_Icon_Critical = 16
axWshShell_Popup_Button_AbortRetryIgnore = 2
axWshShell_Popup_NoAutoclose = 0

intRetVal = axWshShell.Popup(
### Raise a message box:
" The Popup() Text" + "\n" +
"",
axWshShell_Popup_NoAutoclose,
" The Popup() Title:",
axWshShell_Popup_Icon_Critical + axWshShell_Popup_Button_AbortRetryIgnore
)

axWshShell_Popup_Clicked_Abort = 3 # [Abort] button
axWshShell_Popup_Clicked_Retry = 4 # [Retry] button
axWshShell_Popup_Clicked_Ignore = 5 # [Ignore] button

if(intRetVal == axWshShell_Popup_Clicked_Abort):
print 'Abort clicked, return value = %i'%(intRetVal,)

if(intRetVal == axWshShell_Popup_Clicked_Retry):
print 'Retry clicked, return value = %i'%(intRetVal,)

if(intRetVal == axWshShell_Popup_Clicked_Ignore):
print 'Ignore clicked, return value = %i'%(intRetVal,)


To make this example complete, here an excerpt from the registry :

[HKEY_CLASSES_ROOT\CLSID\{72C24DD5-D70A-438B-8A42-98424B88AFB8}\InProcServer
32]
@="E:\\WINNT\\system32\\wshom.ocx"
"ThreadingModel"="Apartment"

[HKEY_CLASSES_ROOT\CLSID\{72C24DD5-D70A-438B-8A42-98424B88AFB8}\VersionIndep
endentProgID]
@="WScript.Shell"


Claudio
P.S. if you face problems with return values or parameter values, one of
reasons can be, that OCXses work always with Unicode strings and you haven't
taken it into consideration.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top