[python-win32] hoto cast pyobject to ccompnt
Tim Roberts
timr at probo.com
Sat Nov 28 02:30:02 EST 2015
On Nov 26, 2015, at 11:34 PM, Matteo Boscolo <matteo.boscolo at boscolini.eu> wrote:
>
> in my cpp code I have my function that recive a com objetc from python
> into args
> from here I'm not able to cast such an object into a ccompnt
>
> static PyObject *
> connect(PyObject * self, PyObject * args)
> {
> PyObject * pyApplication;
> CComPtr<IUnknown> pUnk;
> //try to get active object
> if (!PyArg_ParseTuple(args, "O", &pyApplication))
> return NULL;
> pUnk=(CComPtr<IUnknown> )pyApplication; //<<---- not able to cast
You are just getting a compile-time error, right? That’s because the smart pointer wrapper (CComPtr)will only accept a pointer that actually derives from the type it is wrapping. In this case, that’s not so. You will probably have to force the pointer to be an IUnknown* before you can wrap it in a smart pointer.
pUnk = (IUnknown*)pyApplication;
—
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list