Calling Python Objects from C++ 
Author Message
 Calling Python Objects from C++

Hi -

I'm having problems trying to call a python method from C++ using
OLE/COM. I have a simple python program that publishes a method called
'echo' that writes a string that has been passed to it to a file and then
returns the string back to the caller. Python -> Python doesnt pose any
problems. However, when I try calling it from C++ it all goes horribly
wrong (probably because I havnt programmed in C++ for months). A few

1. What type do I use when calling from C++ if 'echo' wants a string
argument - I've used the automation
wizard (?) in VC++ to build the class and a wrapper for the call. The
online help for this is dire. In VB you just use CreateObject() and call
the object method as you would any other one but you seem to need about
5Meg of code to get even close to this in C++. I've tried VT_BSTR but that
bombs out when 'echo' starts running. I noticed in the help files
something about the varient type being the way to go but it looks
somewhat complicated. Other types either refuse to compile or return
gobbledegook :( Am I off the plot here or what?

2. Calling C++ from Python - how do I make sure that I dont start a new
instance of the object up (equivalent of GetObject(,...) in VB so that I
can run the existing one (if its running)



from StandardDisclaimer import *

Sat, 01 Apr 2000 03:00:00 GMT  
 Calling Python Objects from C++

The problem here is that Python, by default, only supports the IDispatch
interface.  There is no native interface used in this example.

Basically, to use it from C++, you really need to pass VARIANT's, and go
through lots of pain.  The only native methods available are "GetIDsOfNames"
and "Dispatch".  MFC and ATL have some helpers to manage this for you, but
without type information is difficult to use.

In a nutshel, this is very hard, and not what PythonCOM is good at :-(

>2. Calling C++ from Python - how do I make sure that I dont start a new
>instance of the object up (equivalent of GetObject(,...) in VB so that I
>can run the existing one (if its running)

This is more up to the object than anything - some objects dont work as
expected.  But pythoncom.Connect has the same semantics, and
pythoncom.GetActiveObject + a QI is identical (see win32com.hlp - yipee -
something is documented!)


Sat, 08 Apr 2000 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. How to report (and detect) failure from property put calls to C++ COM object from Python

2. calling swigged C++ from C++ via Python?

3. boost::python sharing native c++ object with python

4. c++ calling fortran and fortran calling C++

5. C++ calling Fortran calling C++

6. calling Visual C++ or Prolog calling Visual C++

7. Calling C++ object member functions from ass ?K

8. Calling C++ objects from Fortran

9. Calling C++ objects

10. Using Python COM objects from C++

11. Embeding: C++ Objects visible from Python

12. newbie question: python and c++ objects


Powered by phpBB® Forum Software