Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how come I can not use the Release( ) methord of CComPtr?

how come I can not use the Release( ) methord of CComPtr?

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studiohelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ewighell
    wrote on last edited by
    #1

    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

    R S E 3 Replies Last reply
    0
    • E ewighell

      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

      R Offline
      R Offline
      RChin
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • E ewighell

        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

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • E ewighell

          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

          E Offline
          E Offline
          ewighell
          wrote on last edited by
          #4

          The reason why I have been using the operator "->" is that I always treat a smart pointer as a pointer, now I think it through that it is a object class CComPtr<...> Thank you all very much!!! ------------------- I am learning C++ and English

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups