Interfacing python program to C++ program instance

Discussion in 'Python' started by Jim Langston, Jul 6, 2007.

  1. Jim Langston

    Jim Langston Guest

    Windows. Situation: Using a Python program called OpenRPG. I have a program
    that displays form data (a character sheet) in C++. I am able in the C++
    program to build a string and copy it into the clipboard, then paste it into
    the input in the running Python program.

    I would like to somehow automate this, that is, have the python instance
    communicate with the C++ instance and vice versa. I'm still trying to think
    of a way to do this. There seems to be a number of options, but I'm not
    sure which one is best, or there is a better one.

    1. Write a new C++ program/library with extern C that Python could call.
    This interface program would open up some shared memory that the C++
    application would also open up, and python and C++ could communicate that
    way. Python writing requests to the memory, C++ responding with responses.

    2. Have the C++ program interface directly into the python form, reading
    directly from controls. C++ could write to the input box with reponses.

    3. Have Python write a small file with the request to the HD. Have the C++
    program intermittedly check for the presense of this file. If it exists, it
    would open the file, read the request, write a response file, then delete
    the file Python wrote.

    4. Find out if python can directly, somehow, open up shared memory and do
    the same as 1 without the need for the extern C interface program.

    5. Something else I'm not thinking of but you know.

    Thanks.
     
    Jim Langston, Jul 6, 2007
    #1
    1. Advertising

  2. Jim Langston wrote:
    > Windows. Situation: Using a Python program called OpenRPG. I have a program
    > that displays form data (a character sheet) in C++. I am able in the C++
    > program to build a string and copy it into the clipboard, then paste it into
    > the input in the running Python program.


    If I remember correctly, OpenRPG uses wxPython for it's GUI. wxPython
    offers fairly easy access to the clipboard contents, so it could check
    the clipboard for the kind of data it wants.

    > I would like to somehow automate this, that is, have the python instance
    > communicate with the C++ instance and vice versa. I'm still trying to think
    > of a way to do this. There seems to be a number of options, but I'm not
    > sure which one is best, or there is a better one.
    >
    > 1. Write a new C++ program/library with extern C that Python could call.
    > This interface program would open up some shared memory that the C++
    > application would also open up, and python and C++ could communicate that
    > way. Python writing requests to the memory, C++ responding with responses.


    mmap is the standard "shared memory communication" mechanism available
    on pretty much all platforms of note (Windows, Linux, OSX, BSD, Solaris,
    BeOS, etc.)


    > 2. Have the C++ program interface directly into the python form, reading
    > directly from controls. C++ could write to the input box with reponses.


    If OpenRPG uses any custom controls (which are very easy to write with
    wxPython), this won't be easy. Also, controlling an application that
    wasn't designed for such control can be a beast.


    > 3. Have Python write a small file with the request to the HD. Have the C++
    > program intermittedly check for the presense of this file. If it exists, it
    > would open the file, read the request, write a response file, then delete
    > the file Python wrote.


    This can work, but is unnecessary. See mmap, socket, etc.


    > 4. Find out if python can directly, somehow, open up shared memory and do
    > the same as 1 without the need for the extern C interface program.


    import mmap


    > 5. Something else I'm not thinking of but you know.


    sockets. In particular, XML-RPC for the call/return using structured
    data in XML format. There exists XML-RPC server and client libraries in
    Python, and XML-RPC server and client libraries exist for just about
    every language worth discussing. Alternatively, you can pass your
    queries/string directly via sockets (rather than the clipboard).


    - Josiah
     
    Josiah Carlson, Jul 6, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gandalf

    Interfacing Python crypto library

    Gandalf, Jun 15, 2004, in forum: Python
    Replies:
    0
    Views:
    492
    Gandalf
    Jun 15, 2004
  2. Pramode C E
    Replies:
    0
    Views:
    312
    Pramode C E
    Feb 6, 2005
  3. progpro99
    Replies:
    2
    Views:
    283
    Lucas Raab
    Feb 28, 2005
  4. Replies:
    7
    Views:
    352
  5. Varun Hiremath
    Replies:
    1
    Views:
    492
    Will McGugan
    Sep 18, 2006
Loading...

Share This Page