Is it possible to use CComPtr inside std :: map?

I am writing a program in Windows COM in C ++, and I use CComPtrfor smart pointers.

The question I cannot find the answer to is to use CComPtrinternally std::map.

I have the following code snippet (simplified):

std::map<int, CComPtr<IErrorInfo> > ErrorMap;

I want to keep this mapping between posts intand IErrorInfo.

However, I am not sure if I can do the following:

CComPtr<IErrorInfo> result;
GetErrorInfo(0, &pErrInfo);

ErrorMap.insert(std::make_pair(0, result));

I'm interested in owning a smart pointer result, and if it is correctly released, when ErrorMapwill it be destroyed?

+3
source share
1 answer

You need to wrap your CComPtr in CAdapt for this to work.

CAdapt , (, STL), , , -. , . CAdapt .

+4

All Articles