473,466 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Call OCX from python?

Hi I have a commercial OCX that I want to use in
my python application. How do I call OCXs from
python?
TIA
Nov 26 '05 #1
4 11539
From WxPython, or from PythonWin.

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

Michel Claveau

Nov 26 '05 #2
"JustSomeGuy" <no**@nottelling.com> schrieb im Newsbeitrag
news:5n4if.627200$1i.183531@pd7tw2no...
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("RegistryEntryForThisOCXi n[VersionIndependentProgID
]section")
retVal = axOCX.methodOfThisOCX(param1, param2)
value = axOCX.attributeOfThisOCX

Claudio
Nov 27 '05 #3

"Claudio Grondi" <cl************@freenet.de> wrote in message
news:3u*************@individual.net...
"JustSomeGuy" <no**@nottelling.com> schrieb im Newsbeitrag
news:5n4if.627200$1i.183531@pd7tw2no...
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("RegistryEntryForThisOCXi n[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..
Nov 29 '05 #4

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

"Claudio Grondi" <cl************@freenet.de> wrote in message
news:3u*************@individual.net...
"JustSomeGuy" <no**@nottelling.com> schrieb im Newsbeitrag
news:5n4if.627200$1i.183531@pd7tw2no...
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("RegistryEntryForThisOCXi n[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.
Nov 29 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tubby Tudor | last post by:
What is the best way to call one python script from within another python script? For example: one.py finishes succesfully and calls two.py which finishes OK and then calls three.py Thanks...
4
by: paritosh mahana | last post by:
Hi all, How can I call python code from my C# code. One thing is to make an ..exe file of the python program and then try to call it from my C# code. But I don't like that idea. Is there any...
2
by: FAN | last post by:
I want to define some function in python script dynamicly and call them later, but I get some problem. I have tried the following: ################################## # code...
3
by: evelyne0510 | last post by:
Hi all, I have created a XML-RPC model (with server and client) written in Java. I want to call the methods in another XML-RPC model written in Python. I know that in Java, I can use like...
0
by: Armin Rigo | last post by:
Hi all, A shameless plug and reminder for EuroPython 2006 (July 3-5): * you can submit talk proposals until May 31st. * there is a refereed papers track; deadline for abstracts: May 5th....
5
by: glomde | last post by:
Hi, I tried to write a decorator for that should be for methods but for some reasons it doens seem to work when you try to do it on the __getattr__ method in a class. Could anybody give some...
0
by: arigo | last post by:
Hi all, He're a reminder to submit a talk at EuroPython! Like each year, we have both the regular conference (see call at http://indico.cern.ch/conferenceCFA.py?confId=13919) and a somewhat...
0
by: Nicola Larosa | last post by:
PyCon Uno: Python first Italian conference about Python. Call for Papers =============== Important dedalines ------------------- * April 30, 2007 Submission of paper and tutorial...
2
by: bappai | last post by:
Hello, I am trying to actually call a GUI from my C++ code which would have buttons and therefore can call functions from C++ again, ie extend the C++ code also. I am faced with a peculiar...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.