Search code examples
windowscomidispatch

Can a method be added to an existing dispinterface?


Generally, a method cannot be added to an existing vtable COM interface or dual COM interface, because there may be a derived interface, so expanding the base interface breaks its layout.

But can a method be added to an existing distpinterface? Will it be potentially disruptive for existing users?

Assume the usual use of distpinterface for events, and the usual use of type library, and out-of-process COM server.


Solution

  • as per Igor Tandetnik comment

    If I understand correctly, in your scenario it's the clients that implement the dispinterface, and the server that calls Invoke on them. So the older clients would suddenly have their Invoke implementation called with a DISPID they didn't know existed and weren't prepared to handle. This could theoretically lead to problems -

    client code could do something like

    switch (dispid){ 
      case DISPID_Event1: ... 
      case DISPID_Event2: ... 
      default: /* must be Event3 */ 
    } 
    

    and then have the new Event4 mistaken for Event3