embedded Python calling app via COM

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

    #1

    embedded Python calling app via COM

    I have a C++ app which fires up a Python script using C API calls.
    That script operates the app via Automation calls, like this:

    from win32com.client import *
    from mywrapper import *

    myapp = Application()
    myapp.Visible = True
    mydoc = myapp.Documents .Open(...)

    My problem is to make sure the instance of myapp is the same one I am
    calling from. The above code starts up a new instance of the app,
    which is not what I want. In other words I need something like a
    GetObject instead of a CreateObject, and I need some way to identify
    the calling app so I can tell GetObject about it.

    Before I go and do something hack, I thought I'd see if anyone else is
    in this situation and knows a good way to do the job.

    -- Jim

  • Roger Upole

    #2
    Re: embedded Python calling app via COM


    "Jim" <jim@trainplaye r.com> wrote in message news:1150887820 .604214.276880@ i40g2000cwc.goo glegroups.com.. .[color=blue]
    >I have a C++ app which fires up a Python script using C API calls.
    > That script operates the app via Automation calls, like this:
    >
    > from win32com.client import *
    > from mywrapper import *
    >
    > myapp = Application()
    > myapp.Visible = True
    > mydoc = myapp.Documents .Open(...)
    >
    > My problem is to make sure the instance of myapp is the same one I am
    > calling from. The above code starts up a new instance of the app,
    > which is not what I want. In other words I need something like a
    > GetObject instead of a CreateObject, and I need some way to identify
    > the calling app so I can tell GetObject about it.
    >
    > Before I go and do something hack, I thought I'd see if anyone else is
    > in this situation and knows a good way to do the job.
    >
    > -- Jim[/color]

    Pythoncom.GetAc tiveObject will retrieve the running instance of the app.
    (assuming that it registers itself in the Running Object Table)

    Roger





    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= East/West-Coast Server Farms - Total Privacy via Encryption =---

    Comment

    • Jim

      #3
      Re: embedded Python calling app via COM

      > Pythoncom.GetAc tiveObject will retrieve the running instance of the app.

      Thanks Roger, that does seem to do the trick. I haven't tested to see
      what happens if there are two instances of the app running, I'm hoping
      it will return the frontmost visible one.

      -- Jim

      Comment

      Working...