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. ATL / WTL / STL
  4. How do I work with CComPtr

How do I work with CComPtr

Scheduled Pinned Locked Moved ATL / WTL / STL
question
4 Posts 4 Posters 8 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.
  • J Offline
    J Offline
    Jose Cruz
    wrote on last edited by
    #1

    Can somebody show me how should I work with an CComPtr pointer. Are there any web links wich I can follow.

    P J 2 Replies Last reply
    0
    • J Jose Cruz

      Can somebody show me how should I work with an CComPtr pointer. Are there any web links wich I can follow.

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      CComPtr is a SmartPointer wrapper class specifically designed for COM objects. So when your smart pointer goes out of scope, it will automatically call Release on your object. It is very simple to use. First declare a CComPtr to wrap one of your objects: CComPtr spDataObj; Now you can use spDataObj anywhere that you would normally use a pointer to the interface. You do not need to worry about casting or dereferencing or anything like that it is completely transparent. IUnknown *pUnk; ... pUnk->QueryInterface(IID_IDataObject, &spDataObject); //QueryInterface to assign spDataObj->GetData(...); // call member function of the IDataObject interface. Some other cool things to know are the Attach and Detach members. This will allow you to attach an existing interface pointer to the CComPtr without addrefing it internally, and the Detach method will allow you to remove the internal interface pointer without releasing it. Other than that it should be pretty straight forward, and you may also want to checkout CComQIPtr. That smart pointer object will allow you to query for the interface on assignment, so it will save you one step when you are setting up your pointers. Good Luck


      Build a man a fire, and he will be warm for a day
      Light a man on fire, and he will be warm for the rest of his life!

      1 Reply Last reply
      0
      • J Jose Cruz

        Can somebody show me how should I work with an CComPtr pointer. Are there any web links wich I can follow.

        J Offline
        J Offline
        Jorgen Sigvardsson
        wrote on last edited by
        #3

        Also, check out CComPtr::CoCreateInstance (or was it CreateInstance only?) -- Please state the nature of your medical emergency.

        L 1 Reply Last reply
        0
        • J Jorgen Sigvardsson

          Also, check out CComPtr::CoCreateInstance (or was it CreateInstance only?) -- Please state the nature of your medical emergency.

          L Offline
          L Offline
          Le centriste
          wrote on last edited by
          #4

          it is CoCreateInstance. CreateInstance is with _com_ptr_t. Michel It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
          - TreeBeard

          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