简体   繁体   English

在C#中处理具有不同签名的COM DLL

[英]Handling COM DLLs with different signatures in C#

I'm working with a COM DLL that annoyling has changed one of it's method signatures from Foo(ref ushort bar) to Foo(ref short bar) depending on whatever version the user has installed. 我正在与COM DLL一起使用,根据用户安装的版本,它会被Annoyling将其方法签名之一从Foo(ref ushort bar)更改为Foo(ref short bar)

Performance is crucial, but I can't think of any solution that doesn't involve reflection. 性能至关重要,但是我想不出任何不涉及反思的解决方案。 Has anyone got any ideas? 有人知道吗?

The DLL broke the COM tenet of interface immutability : DLL打破了COM 接口不变性的宗旨:

COM interfaces are immutable . COM接口是不可变的 You cannot define a new version of an old interface and give it the same identifier. 您不能定义旧接口的新版本并为其指定相同的标识符。 Adding or removing methods of an interface or changing semantics creates a new interface, not a new version of an old interface. 添加或删除接口的方法或更改语义会创建一个新接口,而不是旧接口的新版本。 Therefore, a new interface cannot conflict with an old interface. 因此,新接口不能与旧接口冲突。 However, objects can support multiple interfaces simultaneously and can expose interfaces that are successive revisions of an interface, with different identifiers. 但是,对象可以同时支持多个接口,并且可以公开具有不同标识符的接口,这些接口是接口的连续修订版。 Thus, each interface is a separate contract, and system wide objects need not be concerned about whether the version of the interface they are calling is the one they expect. 因此,每个接口都是一个单独的协定,并且系统范围内的对象不必关心它们正在调用的接口的版本是否是他们期望的版本。 The interface ID (IID) defines the interface contract explicitly and uniquely. 接口ID(IID)显式且唯一地定义接口协定。

This is not 'annoying'. 这不是“烦人”。 This is broken . 坏了 The DLL author must define a new interface, with the new signature. DLL作者必须定义一个具有新签名的接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM