Can COM smart pointers be used with the CList collection

I am trying to create a CList with a smart COM pointer (one of the wrapper classes generated for _com_ptr_t) as a template parameter:

CList<IDispatchPtr, IDispatchPtr> list;

However, I get some compilation errors similar to:

error C2664: 'void __stdcall SerializeElements(class CArchive &,class _com_ptr_t<class _com_IIID<struct IDispatch,&struct __s_GUID _GUID_00020400_0000_0000_c000_00000000004 6> > *,int)' : cannot convert parameter 2 from 'struct IDispatch ** ' to 'class _com_ptr_t<class _com_IIID<struct IDispatch,&struct __s_GUID _GUID_00020400_0000_0000_c000_000000000046> > *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

It compiles using regular pointers:

CList<IDispatch*, IDispatch*> list;

Looking at the MFC code that calls SerializeElements, the problem seems to be that it accepts TYPE * and there is no conversion between IDispatch** and IDispatchPtr*. Is there any way around this?

+3
source share
1 answer

Due to overload, operator&you need to wrap smart pointers in CAdapt<>:

CList<CAdapt<IDispatchPtr>, CAdapt<IDispatchPtr> > list;
+5
source

Source: https://habr.com/ru/post/1721743/


All Articles