Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Interfacing python program to C++ program instance

Reply
Thread Tools

Interfacing python program to C++ program instance

 
 
Jim Langston
Guest
Posts: n/a
 
      07-06-2007
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.


 
Reply With Quote
 
 
 
 
Josiah Carlson
Guest
Posts: n/a
 
      07-06-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interfacing my chess client with GNU chess using python Varun Hiremath Python 1 09-18-2006 05:24 PM
Python:C++ interfacing. Tool selection recommendations adsheehan@eircom.net Python 7 09-19-2005 10:55 AM
Python interfacing with other languages progpro99 Python 2 02-28-2005 01:06 PM
Python scripts a PC Interfacing equipment Pramode C E Python 0 02-06-2005 10:26 AM
Interfacing Python crypto library Gandalf Python 0 06-15-2004 11:37 AM



Advertisments