• Advertisement
Sign in to follow this  

control C++ app from python

This topic is 4506 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I have an mfc GUI application, which I need to control externally. What I'd like to do is provide a python api (using the excellent boost.python library) and control it using a python script. I have the api defined, but I need some way of tying the script to a running instance of the app, so that api calls affect the running instance of the application. so what I have is app.exe, appAPI.dll (this exposes the python interface) and a python script that calls methods of the api. what I need is something like
class PyAPI // exported to python
{
   AppDlg* appInst; 
   PyAPI()
   {
       appInst = GetPointerToRunningInstanceOfApp();
   }

   void dosomething()
   {
      appInst->dosomething();
   }
}
any ideas? is this even possible? would I be better off using some sort of IPC? all suggestions appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Do you want the script to be an external process, or do you want to embed Python in your application?

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Do you want the script to be an external process, or do you want to embed Python in your application?


preferrably an external process, but I'm open to ideas.

Share this post


Link to post
Share on other sites
If you want the python script to be an external process, then your best bet is probably to automate your program using COM. Since you are using MFC it shouldn't be too difficult, just annoying. Look up "Automation Servers" and "IDispatch" and the "AUTOCLIK" sample MFC application. Your Python script will then need to use win32com to dispatch to the automation server.

On the other hand, if you want your python scripts to be run in the same process, things are significantly simpler. Just embed Python in your application, and take the API that you wanted to expose and wrap that in a normal BOOST_PYTHON_MODULE declaration. Remember to initialize the module after you call Py_Initialize() and you should be set.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement