I want to add a new method to a COM interface with all the existing one unchanged, will this break its compatibility for the consumer before this update?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends: if this is an internal unpublished interface, you are free to change it at will so long as you control all the code that interacts with that interface.
Once published, however, the rules are strict: every interface has its own IID. You change that interface in any way – by modifying, adding or removing methods – it’s a whole new interface, and requires a new IID.
However: COM does doesn’t care how that new interface is implemented: so you can have your class implement it as a derivation of the old interface that just adds a new method, and have your implementation class implement the derivation, so long as QI returns a suitable interface when asked for either the old or new interface.
For example:
So, while you are technically “adding another interface”, you’re actually adding little code here: just defining a new interface that derived from the old one, changing the interface your class implements to the new one (and adding the implementation for the new method), and finally updating QI to support both the old and new methods – returning the same interface for both (and for IUnknown too).