Click here to Skip to main content
15,921,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have a COM/DCOM component (dll) which have several interface. In one of those interface, I want to modify a method but I don't want to proceed to the compil of my client. On the paper I know it is not possible but...

The concerned method (in the events interface) contains several args but one of the argument (input) is a pointer to a structure.

My question is : If I add a param (Byte for example) at the end of my structure, should I rebuild my (old) client or does it works fine ? (My old client will read the old structure without the Byte element and the new client will read the structure with the Byte element).

Thanks in advance

This is a complicated question for which the answer is, "it depends". For example if a proxy/stub is involved, as is the case in a cross-process situation, the extra byte will probably not be marshalled correctly (as the data use to generate the proxy/stub doesn't include the byte). Unless you really know what you're doing it's best just to follow the rules. Also, given that COM is largly just a collection of rules and conventions (there is a runtime component too, obviously) why use it if you're going to break them? Also, breaking the rules (or even bending them in some cases) can bite you the future. One example of this is integration with other languages (such as C# or VB) often depends on the data in the type library being correct.

The COM way to add new features and not break existing clients it to simply add a new interface.
Share this answer
I don't think it's even safe to do this, because although you only have a pointer to the struct it's possible that there may be a proxy/marshalling situation where the size of the struct comes into play. If your actual struct is larger than what the code expects it to be (because of the extra byte member) you could overwrite memory and get unexpected errors/side results. Even if you test this out and find it to be safe today, it's not guaranteed to be safe in future.
Share this answer
In theory (and generally in practice) this should work. However, it is considered bad programming practice and should be avoided if possible. Much better to rebuild your client so it is aware of the new structure.
Share this answer
Hans Dietrich 31-Jan-11 11:05am    
Good answer. (Don't understand the 1-vote.) I would add that if this situation is likely to occur again, then maybe there should be a 'size' member in the struct.
Richard MacCutchan 31-Jan-11 12:32pm    
Thanks, 1-votes don't worry me. I did note some of the comments about marshalling in the other answers which could be pertinent.
I agree with you but some client are not developped by me and I can't rebuild them.

It's pity to have some different interface with quite similar method... If I forget a param at the creation of a method, I have to create a new interface with a new method and I have to call both methods. (... with a third interface if a new param has to be created in few months ...).

It's not complicated to create a new interface but I don't think it's X| to have to call two or more methods to do tha same thing (just because I forgot a param at its creation).

Thanks for your response :thumbsup: : I will create a new interface :doh:
Share this answer
Stephen Hewitt 31-Jan-11 11:39am    
One thing which may be applicable is to derive the new interface from the old one and simply add some extra methods. I don;t know your exact sutuation however.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900