COM前向兼容性? [英] COM Forward compatibility ?

查看:98
本文介绍了COM前向兼容性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有一个问题。我有一个与版本A的DLL COM,我有这个DLL的新版本(版本B)。版本B支持向后兼容,即:当我用dll的版本A编译应用程序时,它工作正常。当我们在安装了B版本的机器上启动时。



我想我的描述很清楚:(



现在如果逆是真的话我需要什么?

ie:如果我使用新版本的dll(版本B)编译我的应用程序并在具有该版本的机器上启动我的应用程序已安装。是否可行?

解决方案

COM 有严格的规则:接口必须是不可变的。你必须永远不要在新版本的 COM DLL 中更改界面。但是你可以添加接口。

现在,假设您(严格地)遵循 COM 规则,新的 DLL ,支持旧接口,可能如果对象B依赖于其中一个新接口,则在旧的 COM DLL QueryInterface 将失败$ c>。


一般情况下,不是。实际上,那个'为什么,除了兼容性,COM组件应该支持版本。



现在,为什么呢?要理解它,你应该考虑接口指针指向的内存布局和两个方面:组件和使用代码。这是插图。从C ++的角度来看,将其视为伪代码:

  //  旧组件: 
interface A {
MethodOne();
}

// 新组件:
interface A {
MethodOne();
MethodTwo();
}

// 旧的使用代码:
a a = // ...
a.MethodOne(); // 适用于新旧版本的A

// 新使用代码:
A a = // ...
a.MethodOne(); // 适用于新旧版本的A
// ,一般情况下:
a.MethodTwo(); // 对新版本的A有效,将尝试调用旧版本A的不存在方法





你明白了吗?



-SA

Hello, I have a question. I have a dll COM with version A and I have a new version of this dll (version B). Version B supports backward compatibility i.e: When I compile application with the version A of dll it works fine. When we launch it on machine that has version B installed.

I suppose my description is clear :(

Now what do I need if the inverse is true or not?
i.e : If I compile my application with the new version of dll(version B) and launch my application on machine which have the version A installed. Will this work or not?

解决方案

COM has strict rules: Interfaces must be immutable. You must never, ever change the interface in a new version of a COM DLL. You may add interfaces, however.
Now, supposing you have (strictly) followed the COM rules, the new DLL, supports the old interface and possibly new ones. IF object B relies on one of the new interfaces, then the corrensponding QueryInterface would fail when called on the old COM DLL.


In general case, not. Actually, that''s why, in addition to compatibility, COM components should support versioning.

Now, why? To understand it, you should consider layout of memory pointed by interface pointer and two side: a component and using code. Here is the illustration. From C++ perspective, consider it as pseudo-code:

//Old component:
interface A {
   MethodOne();
}

//New component:
interface A {
   MethodOne();
   MethodTwo();
}

//Old using code:
A a = //...
a.MethodOne(); // valid for both new and old versions of A

//New using code:
A a = //...
a.MethodOne(); // valid for both new and old versions of A
// and, in general case:
a.MethodTwo(); // valid for new version of A, will try to call non-existent method of old version of A



Are you getting the idea?

—SA


这篇关于COM前向兼容性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆