CComPtr

This is a discussion on CComPtr within the Windows Programming forums, part of the Platform Specific Boards category; Hello everyone, In the book ATL Internals, it is mentioned, the properties of CComPtr is, -------------------- Release the encapsulated interface ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    CComPtr

    Hello everyone,


    In the book ATL Internals, it is mentioned, the properties of CComPtr is,

    --------------------
    Release the encapsulated interface pointer when the class destructor executes;
    Automatically releases its interface pointer during exception handling, ...
    --------------------

    They both means invoking the Relase method (inherited from IUnknown) of the interface?


    thanks in advance,
    George

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    Yes, that's what it does! It calls Release when appropriate, and AddRef when you assign a new handle to it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,293
    Yes in both cases the destructor is called which calls Release.

    I find CComPtr to be fairly good. The only downsides I find are the lack of an operator < for use in sets etc. (Note that to use a CComPtr in a std container etc you sometimes need to wrap it in a CAdapt as well anyway)
    It's IsEqualObject function is a little sub-optimal too, but there is a site on the net somewhere showing the optimisation for it. The VS2008 implementation doesn't offer any improvement here from what I've seen. Still, on the whole they're rather good.

    Other alternatives like IUnknownPtr lack a lot of const-correctness, making things like their operator < a bit useless.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Elysia,


    Clear reply.

    Quote Originally Posted by Elysia View Post
    Yes, that's what it does! It calls Release when appropriate, and AddRef when you assign a new handle to it.

    Thanks iMalc,


    Two more comments,

    1.

    Quote Originally Posted by iMalc View Post
    Yes in both cases the destructor is called which calls Release.

    I find CComPtr to be fairly good. The only downsides I find are the lack of an operator < for use in sets etc. (Note that to use a CComPtr in a std container etc you sometimes need to wrap it in a CAdapt as well anyway)
    Confused. CAdapt is used for rewrite the address of operator -- &. How could you use it to re-write operator <?

    Here is what MSDN said,

    (http://msdn2.microsoft.com/en-us/library/bs6acf5x.aspx)

    --------------------
    This template is used to wrap classes that redefine the address-of operator to return something other than the address of the object.
    --------------------


    2.

    Quote Originally Posted by iMalc View Post
    It's IsEqualObject function is a little sub-optimal too, but there is a site on the net somewhere showing the optimisation for it. The VS2008 implementation doesn't offer any improvement here from what I've seen. Still, on the whole they're rather good.

    Other alternatives like IUnknownPtr lack a lot of const-correctness, making things like their operator < a bit useless.
    Interested in it. Could you refer some links about what you mean what is the performance degration and how to optimize IsEqualObject please?


    regards,
    George

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    Quote Originally Posted by iMalc View Post
    The VS2008 implementation doesn't offer any improvement here from what I've seen. Still, on the whole they're rather good.
    On what?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Elysia,


    I mean I want to learn from iMalc about how other people optimize IsEqualObject function, this is what he said before "It's IsEqualObject function is a little sub-optimal too"

    Quote Originally Posted by Elysia View Post
    On what?

    regards,
    George

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    On what was aimed at iMalc since I quoted the part of the text I was curious about.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Me too, Elysia.


    Let us wait for his reply. :-)

    Quote Originally Posted by Elysia View Post
    On what was aimed at iMalc since I quoted the part of the text I was curious about.

    regards,
    George

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,293
    Hi guys, this is the article I was talking about:
    http://www.codeproject.com/KB/bugs/w...s.aspx#CComPtr

    Basically with the original code it calls QueryInterface on both objects even when the pointer values are identical. QI need only be used when the pointer are from different interfaces of the same object.
    Last edited by iMalc; 04-05-2008 at 02:28 AM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  10. #10
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks iMalc,


    I looked through the code you posted, and the optimization method looks good. :-)

    BTW: What is the relationship between the article and code you referred below and my original question?

    Quote Originally Posted by iMalc View Post
    Hi guys, this is the article I was talking about:
    http://www.codeproject.com/KB/bugs/w...s.aspx#CComPtr

    Basically with the original code it calls QueryInterface on both objects even when the pointer values are identical. QI need only be used when the pointer are from different interfaces of the same object.

    regards,
    George

  11. #11
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,293
    Quote Originally Posted by George2 View Post
    I looked through the code you posted, and the optimization method looks good. :-)

    BTW: What is the relationship between the article and code you referred below and my original question?
    Oh, I was just mentioning some of the good and bad things I've found about that class, since you were interested in it.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  12. #12
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Cool, iMalc!


    Thanks for clarifying that. :-)

    Quote Originally Posted by iMalc View Post
    Oh, I was just mentioning some of the good and bad things I've found about that class, since you were interested in it.

    have a good day,
    George

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ATL bug of CComPtr?
    By George2 in forum Windows Programming
    Replies: 6
    Last Post: 04-07-2008, 07:52 AM
  2. 'now playing' code for windows media player?
    By X PaYnE X in forum Windows Programming
    Replies: 0
    Last Post: 05-25-2006, 02:23 AM
  3. Why is this not working??? PLEASE HELP ANYONE!!!!
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 06-26-2002, 01:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21