Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Call OCX from python?

60 views
Skip to first unread message

JustSomeGuy

unread,
Nov 26, 2005, 4:23:13 PM11/26/05
to
Hi I have a commercial OCX that I want to use in
my python application. How do I call OCXs from
python?
TIA


Do Re Mi chel La Si Do

unread,
Nov 26, 2005, 4:40:14 PM11/26/05
to
From WxPython, or from PythonWin.

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

Michel Claveau

Claudio Grondi

unread,
Nov 26, 2005, 10:48:31 PM11/26/05
to
"JustSomeGuy" <no...@nottelling.com> schrieb im Newsbeitrag
news:5n4if.627200$1i.183531@pd7tw2no...

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

Claudio


JustSomeGuy

unread,
Nov 28, 2005, 6:51:17 PM11/28/05
to

"Claudio Grondi" <claudio...@freenet.de> wrote in message
news:3usl5aF...@individual.net...

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


Claudio Grondi

unread,
Nov 29, 2005, 4:27:35 AM11/29/05
to

"JustSomeGuy" <no...@nottelling.com> schrieb im Newsbeitrag
news:VJMif.646622$tl2.454656@pd7tw3no...

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.


0 new messages