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. COM concept help - order of functions or parameters

COM concept help - order of functions or parameters

Scheduled Pinned Locked Moved COM
questioncomperformancehelptutorial
3 Posts 2 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.
  • J Offline
    J Offline
    J B 0
    wrote on last edited by
    #1

    Hi guys, as I recently dig into the world of COM by reading Inside COM by Dale Rogerson, I encounter this question in the early chapters. In the book it says you should always make a new version of interface when - Order of functions in an interface changes - Order of pamaters in an function changes What exactly do this imply? The order as in the position order the fuctions or parameters listed out? For example: interface IX : IUnknown { virtual void __stdcall Fx() = 0; virtual void __stdcall Fy() = 0; }; changes to interface IX : IUnknown { virtual void __stdcall Fy() = 0; virtual void __stdcall Fx() = 0; }; if it is what the book means, when it says that a new version is required, is it because that the virtual function table are no longer the same for the above two interfaces, where the functions (or in other case parameters) would reside in different memory block addresses?:confused: Thanks~

    S 1 Reply Last reply
    0
    • J J B 0

      Hi guys, as I recently dig into the world of COM by reading Inside COM by Dale Rogerson, I encounter this question in the early chapters. In the book it says you should always make a new version of interface when - Order of functions in an interface changes - Order of pamaters in an function changes What exactly do this imply? The order as in the position order the fuctions or parameters listed out? For example: interface IX : IUnknown { virtual void __stdcall Fx() = 0; virtual void __stdcall Fy() = 0; }; changes to interface IX : IUnknown { virtual void __stdcall Fy() = 0; virtual void __stdcall Fx() = 0; }; if it is what the book means, when it says that a new version is required, is it because that the virtual function table are no longer the same for the above two interfaces, where the functions (or in other case parameters) would reside in different memory block addresses?:confused: Thanks~

      S Offline
      S Offline
      Steve S
      wrote on last edited by
      #2

      Yes. If you change the order of the functions in the declaration, their positions in the interface will shift. When you derive from IUnknown, for example, you rely on the compiler putting in QueryInterface as func#0, AddRef as func#1, and Release as func#2. When you declare the first version, Fx is func#3, and Fy is func#4. By rewriting as the second version, the positions of Fx and Fy are swapped. This matters because COM is a binary standard, for cross-language use. If you have a client that calls methods on this interface, it is quite likely doing so by locating the function in a table. If you change the order, the table is invalid, and a call to Fx by the client would be a call to Fy instead. Replace the names 'Fx' with 'Save' and 'Fy' with 'Delete' and you'll see why this is important. You could get around this problem by recompiling all clients, but if you haven't got source for all of them, you wouldn't be able to do this, of course. Similarly, if you alter the order of parameters (or types, or add/remove parameters), again, this alters the shape of the interface, so you should use a new one. Of course, while you're developing the first version, it's quite conceivable that halfway through, you'll need to change the interface, and within reason, you're able to do that without generating a new UUID (or IID) for it, but as soon as you've published it (which in general terms means installed on other than development kit), the interface should be regarded as immutable. Steve S Developer for hire

      J 1 Reply Last reply
      0
      • S Steve S

        Yes. If you change the order of the functions in the declaration, their positions in the interface will shift. When you derive from IUnknown, for example, you rely on the compiler putting in QueryInterface as func#0, AddRef as func#1, and Release as func#2. When you declare the first version, Fx is func#3, and Fy is func#4. By rewriting as the second version, the positions of Fx and Fy are swapped. This matters because COM is a binary standard, for cross-language use. If you have a client that calls methods on this interface, it is quite likely doing so by locating the function in a table. If you change the order, the table is invalid, and a call to Fx by the client would be a call to Fy instead. Replace the names 'Fx' with 'Save' and 'Fy' with 'Delete' and you'll see why this is important. You could get around this problem by recompiling all clients, but if you haven't got source for all of them, you wouldn't be able to do this, of course. Similarly, if you alter the order of parameters (or types, or add/remove parameters), again, this alters the shape of the interface, so you should use a new one. Of course, while you're developing the first version, it's quite conceivable that halfway through, you'll need to change the interface, and within reason, you're able to do that without generating a new UUID (or IID) for it, but as soon as you've published it (which in general terms means installed on other than development kit), the interface should be regarded as immutable. Steve S Developer for hire

        J Offline
        J Offline
        J B 0
        wrote on last edited by
        #3

        Hi Steve, wow, thanks for the reply. That's the best answer I could've asked for. Thanks again! J.B.

        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