[python-win32] Passing IDispatch from a C program to Python -- Is it possible?
Finn Bragason
fbragason@cggenesisproject.com
Wed, 5 Feb 2003 10:00:21 +1100
Thanks for quick response Mark.
Can you give me some more info on how to use the pythoncomxx.dll (an
example would be great).
Thanks,
Fin
-----Original Message-----
From: Mark Hammond [mailto:mhammond@skippinet.com.au]
Sent: Tuesday, 4 February 2003 4:50 PM
To: Finn Bragason; python-win32@python.org
Subject: RE: [python-win32] Passing IDispatch from a C program to Python
-- Is it possible?
If you link to pythoncomxx.dll, you can use any of the functions in
pythoncom.h specifically for this purpose.
Mark.
> -----Original Message-----
> From: python-win32-admin@python.org
> [mailto:python-win32-admin@python.org]On Behalf Of Finn Bragason
> Sent: Tuesday, 4 February 2003 3:44 PM
> To: python-win32@python.org
> Subject: [python-win32] Passing IDispatch from a C program to=20
> Python --
> Is it possible?
>=20
>=20
> I want to create a COM object in a C/C++ program and pass it to an
> embedded Python program.
> So my C/C++ program is something like:
>=20
> // converter function
> int converter(PyObject * obj, void * p)
> {
> // Initialise obj with p -- somehow
> return 1;
> }
>=20
>=20
> main()
> ...
> // create a COM object
> IConnectPtr conn;;
> HRESULT hr =3D conn.CreateInstance(__uuidof(Connect));
> ... do something with conn
> // Do the Python embedding initialise
> Py_Initialize();
> ..etc..etc
> // Create a PyObject from the conn Interface to pass to Python
> PyObject * p =3D Py_BuildValue("O&", converter, *conn);
> // Set the newly created object as a parameter to python
> PyTuple_SetItem(pArgs, 1, p);
> // Call Python
> PyObject_CallObject(func, pArgs);
>=20
> My Python program would be something like:
> def func(conn):
> # Test if conn object is connected
> if conn.IsConnected:
> # do something with it
>=20
> Any comments greatly appreciated.
> Fin
>=20
>=20
> _______________________________________________
> Python-win32 mailing list
> Python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32
>=20