[python-win32] hoto cast pyobject to ccompnt

Matteo Boscolo matteo.boscolo at boscolini.eu
Sat Nov 28 03:02:24 EST 2015


Il 28/11/2015 08:30, Tim Roberts ha scritto:
> 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.
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> https://mail.python.org/mailman/listinfo/python-win32
>
thanks for your replay..
but if i made the suggested cast i get
../pyThinkdesign.cpp(59) : error C2259: 'IUnknown' : cannot instantiate 
abstract class
         due to following members:
         'HRESULT IUnknown::QueryInterface(const IID &,void **)' : is 
abstract
         C:\Program Files\Microsoft 
SDKs\Windows\v6.0A\include\unknwn.h(116) : see declaration of 
'IUnknown::QueryInterface'
         'ULONG IUnknown::AddRef(void)' : is abstract
         C:\Program Files\Microsoft 
SDKs\Windows\v6.0A\include\unknwn.h(120) : see declaration of 
'IUnknown::AddRef'
         'ULONG IUnknown::Release(void)' : is abstract
         C:\Program Files\Microsoft 
SDKs\Windows\v6.0A\include\unknwn.h(122) : see declaration of 
'IUnknown::Release'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 
9.0\\VC\\BIN\\cl.exe' failed with exit status 2

best refgards
Matteo


---
Questa e-mail è stata controllata per individuare virus con Avast antivirus.
http://www.avast.com



More information about the python-win32 mailing list