是否重建我的客户? (COM/DCOM-C ++)

问题描述:

您好

我有一个COM/DCOM组件(dll),它具有多个接口.在这些界面之一中,我想修改一个方法,但不想继续进行客户端的编译.在纸上,我知道这是不可能的,但是...

有关的方法(在events接口中)包含几个args,但是参数(输入)之一是指向结构的指针.

我的问题是:如果我在结构的末尾添加一个参数(例如Byte),我应该重建我的(旧)客户端还是可以正常工作? (我的旧客户端将读取不带Byte元素的旧结构,而新客户端将读取带Byte元素的结构).

在此先感谢

Hi

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

这是一个复杂的问题,答案是取决于".例如,如果涉及代理/存根,则在跨进程情况下,多余的字节可能不会正确编组(因为用于生成代理/存根的数据不包含该字节).除非您真的知道自己在做什么,否则最好遵循规则.另外,鉴于COM只是一个大的规则和约定的集合(显然也有一个运行时组件),如果您要破坏它们,为什么还要使用它呢?此外,违反规则(甚至在某些情况下甚至违反规则)也可能给您带来未来的痛苦.这样的一个例子是与其他语言(例如C#或VB)的集成通常取决于类型库中的数据是否正确.

COM添加新功能而不破坏现有客户端的方式只是添加一个新接口.
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.


我认为这样做并不安全,因为尽管您仅具有指向该结构的指针,可能会出现结构的大小起作用的代理/编组情况.如果您的实际结构大于代码期望的大小(由于额外的字节成员),则可能会覆盖内存并获得意外的错误/其他结果.即使您对此进行了测试并发现它今天是安全的,也不能保证将来会安全.
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.


从理论上(通常是在实践中),这应该可行.但是,这被认为是不良的编程习惯,应尽可能避免使用.重建客户端要好得多,这样它才能知道新的结构.
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.