Call OCX from python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JustSomeGuy

    #1

    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


  • Do Re Mi chel La Si Do

    #2
    Re: Call OCX from python?

    From WxPython, or from PythonWin.

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

    Michel Claveau



    Comment

    • Claudio Grondi

      #3
      Re: Call OCX from python?

      "JustSomeGu y" <nope@nottellin g.com> schrieb im Newsbeitrag
      news:5n4if.6272 00$1i.183531@pd 7tw2no...[color=blue]
      > Hi I have a commercial OCX that I want to use in
      > my python application. How do I call OCXs from
      > python?
      > TIA[/color]

      import win32com.client
      axOCX =
      win32com.client .Dispatch("Regi stryEntryForThi sOCXin[VersionIndepend entProgID
      ]section")
      retVal = axOCX.methodOfT hisOCX(param1, param2)
      value = axOCX.attribute OfThisOCX

      Claudio


      Comment

      • JustSomeGuy

        #4
        Re: Call OCX from python?


        "Claudio Grondi" <claudio.grondi @freenet.de> wrote in message
        news:3usl5aF12j a39U1@individua l.net...[color=blue]
        > "JustSomeGu y" <nope@nottellin g.com> schrieb im Newsbeitrag
        > news:5n4if.6272 00$1i.183531@pd 7tw2no...[color=green]
        > > Hi I have a commercial OCX that I want to use in
        > > my python application. How do I call OCXs from
        > > python?
        > > TIA[/color]
        >
        > import win32com.client
        > axOCX =
        >[/color]
        win32com.client .Dispatch("Regi stryEntryForThi sOCXin[VersionIndepend entProgID[color=blue]
        > ]section")
        > retVal = axOCX.methodOfT hisOCX(param1, param2)
        > value = axOCX.attribute OfThisOCX
        >
        > Claudio
        >
        >[/color]

        Thank you Claudio...
        Can you explain the RegistryEntryFo rThisOcxin[VersionIndepend entProgID]
        I don't know what I should use here..


        Comment

        • Claudio Grondi

          #5
          Re: Call OCX from python?


          "JustSomeGu y" <nope@nottellin g.com> schrieb im Newsbeitrag
          news:VJMif.6466 22$tl2.454656@p d7tw3no...[color=blue]
          >
          > "Claudio Grondi" <claudio.grondi @freenet.de> wrote in message
          > news:3usl5aF12j a39U1@individua l.net...[color=green]
          > > "JustSomeGu y" <nope@nottellin g.com> schrieb im Newsbeitrag
          > > news:5n4if.6272 00$1i.183531@pd 7tw2no...[color=darkred]
          > > > Hi I have a commercial OCX that I want to use in
          > > > my python application. How do I call OCXs from
          > > > python?
          > > > TIA[/color]
          > >
          > > import win32com.client
          > > axOCX =
          > >[/color]
          >[/color]
          win32com.client .Dispatch("Regi stryEntryForThi sOCXin[VersionIndepend entProgID[color=blue][color=green]
          > > ]section")
          > > retVal = axOCX.methodOfT hisOCX(param1, param2)
          > > value = axOCX.attribute OfThisOCX
          > >
          > > Claudio
          > >
          > >[/color]
          >
          > Thank you Claudio...
          > Can you explain the RegistryEntryFo rThisOcxin[VersionIndepend entProgID]
          > I don't know what I should use here..[/color]

          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 [VersionIndepend entProgID] 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
          [VersionIndepend entProgID] 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("WScr ipt.Shell") # WSHOM.OCX

          axWshShell_Popu p_Icon_Critical = 16
          axWshShell_Popu p_Button_AbortR etryIgnore = 2
          axWshShell_Popu p_NoAutoclose = 0

          intRetVal = axWshShell.Popu p(
          ### Raise a message box:
          " The Popup() Text" + "\n" +
          "",
          axWshShell_Popu p_NoAutoclose,
          " The Popup() Title:",
          axWshShell_Popu p_Icon_Critical + axWshShell_Popu p_Button_AbortR etryIgnore
          )

          axWshShell_Popu p_Clicked_Abort = 3 # [Abort] button
          axWshShell_Popu p_Clicked_Retry = 4 # [Retry] button
          axWshShell_Popu p_Clicked_Ignor e = 5 # [Ignore] button

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

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

          if(intRetVal == axWshShell_Popu p_Clicked_Ignor e):
          print 'Ignore clicked, return value = %i'%(intRetVal, )


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

          [HKEY_CLASSES_RO OT\CLSID\{72C24 DD5-D70A-438B-8A42-98424B88AFB8}\I nProcServer
          32]
          @="E:\\WINNT\\s ystem32\\wshom. ocx"
          "ThreadingModel "="Apartmen t"

          [HKEY_CLASSES_RO OT\CLSID\{72C24 DD5-D70A-438B-8A42-98424B88AFB8}\V ersionIndep
          endentProgID]
          @="WScript.Shel l"


          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.


          Comment

          Working...