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. COM
  4. QueryInterface()

QueryInterface()

Scheduled Pinned Locked Moved COM
question
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.
  • S Offline
    S Offline
    skruss
    wrote on last edited by
    #1

    Hi, Could anybody explain why in QueryInterface()we use static_cast for casting pointers to interfaces to be returned by the functions, but inside the function in order to call AddRef() we call reintepret_cast like this: reinterpret_cast(*ppv)->AddRef();? Why not just using static_cast as well? Any input would be of great value and much appreciated. Thanks. skruss

    E J 2 Replies Last reply
    0
    • S skruss

      Hi, Could anybody explain why in QueryInterface()we use static_cast for casting pointers to interfaces to be returned by the functions, but inside the function in order to call AddRef() we call reintepret_cast like this: reinterpret_cast(*ppv)->AddRef();? Why not just using static_cast as well? Any input would be of great value and much appreciated. Thanks. skruss

      E Offline
      E Offline
      ekklesia
      wrote on last edited by
      #2

      if you find these words like static_cast,reintepret_cast and dynamic_cast on msdn you will find the answer. nice to meet u

      S 1 Reply Last reply
      0
      • S skruss

        Hi, Could anybody explain why in QueryInterface()we use static_cast for casting pointers to interfaces to be returned by the functions, but inside the function in order to call AddRef() we call reintepret_cast like this: reinterpret_cast(*ppv)->AddRef();? Why not just using static_cast as well? Any input would be of great value and much appreciated. Thanks. skruss

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

        skruss wrote: Why not just using static_cast as well? It's a matter of taste really. They exist so that you can tell the compiler what it is that you want to accomplish. That way, the compiler can issue warnings/errors if what you want to do is illegal. Of course, dynamic_cast is slightly different from the other casting operators in that it actually does the cast in runtime (it returns 0 if A is not assignable to B - B* b = dynamic_cast<A*> reinterpret_cast should be avoided unless you really need it. Why? Because it basically tells the compiler to cast whatever into whatever. The compiler can thus not issue any warnings/errors. -- Booohoo!

        1 Reply Last reply
        0
        • E ekklesia

          if you find these words like static_cast,reintepret_cast and dynamic_cast on msdn you will find the answer. nice to meet u

          S Offline
          S Offline
          skruss
          wrote on last edited by
          #4

          Thanks very much. I looked their and found it very helpful indeed. Nice to meet you too. skruss

          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