how come I can not use the Release( ) methord of CComPtr?
-
whenever I use it, following "build error" shows up: F:\hu\DD\DetailDesign\ProfileFeatureCmd.cpp(2850) : error C2248: 'Release' : cannot access private member declared in class 'ATL::_NoAddRefReleaseOnCComPtr' d:\program files\microsoft visual studio\vc98\atl\include\atlbase.h(420) : see declaration of 'Release' Thank you very much!!! ------------------- I am learning C++ and English
-
whenever I use it, following "build error" shows up: F:\hu\DD\DetailDesign\ProfileFeatureCmd.cpp(2850) : error C2248: 'Release' : cannot access private member declared in class 'ATL::_NoAddRefReleaseOnCComPtr' d:\program files\microsoft visual studio\vc98\atl\include\atlbase.h(420) : see declaration of 'Release' Thank you very much!!! ------------------- I am learning C++ and English
Instead of calling the underlying interface's Release function, call the class's Release method. So, instead of :
pMyInterface->Release();
Try:pMyInterface.Release();
<EDIT> But the ATL class will do this automatically for you when it goes out of scope, so you don't need to explicitly do this< ;EDIT>* * *I Dream of Absolute Zero -- modified at 9:07 Sunday 16th April, 2006
-
whenever I use it, following "build error" shows up: F:\hu\DD\DetailDesign\ProfileFeatureCmd.cpp(2850) : error C2248: 'Release' : cannot access private member declared in class 'ATL::_NoAddRefReleaseOnCComPtr' d:\program files\microsoft visual studio\vc98\atl\include\atlbase.h(420) : see declaration of 'Release' Thank you very much!!! ------------------- I am learning C++ and English
This is by design. The reason in that when you call
Release
through a smart pointer you've probably just introduced a bug into your code - So ATL disallows it. He's some code which shows why this is the case:{ CComPtr<IDispatch> spDisp; CoCreateInstance(CLSID_SomeObject, NULL, CLSCTX_ALL, IID_IDispatch, reinterpret_cast<void**>(&spDisp)); // At this point there is one reference to the object held by our smart pointer. spDisp->Release(); // ATL will not allow this. If it did, after this the reference count is zero but the // smart pointer still "thinks" it owns a reference. } // At this point the smart pointer will attempt to `Release` its reference. // As mentioned earlier the reference count is actually zero so this will probably end // in disaster (if you're lucky, quickly).
Steve -
whenever I use it, following "build error" shows up: F:\hu\DD\DetailDesign\ProfileFeatureCmd.cpp(2850) : error C2248: 'Release' : cannot access private member declared in class 'ATL::_NoAddRefReleaseOnCComPtr' d:\program files\microsoft visual studio\vc98\atl\include\atlbase.h(420) : see declaration of 'Release' Thank you very much!!! ------------------- I am learning C++ and English