如何为类型库转换制作合适的.DLL

How To Make A Suitable .DLL for type-library conversion

本文关键字:DLL 转换 类型      更新时间:2023-10-16

我的 COM 类型库.tlb(由.NET v4+regasm生成)中存在不完整的类型,我不确定这是因为cppc.exe派生了错误的标头,还是这只是它的症状。 我知道这是不完整的,因为所有生成的类都以 a. 作为structs 和 b. 的空接口主体(未定义方法)。

我敢肯定,在使我的.dll适合加油时,我做错了什么;我已经更改了程序集信息,并为所有类型的构造函数制作了默认构造函数。我是否打算做其他事情?

如果将程序集标记为 COM 可见,则在dispinterface的帮助下,所有具有默认构造函数的公共类都会公开。此接口类型专为后期绑定客户端(如脚本语言)而设计,这些客户端通过调度标识符 (DISPID) 调用方法和属性。随附的类型库不包含接口的任何条目。

为了绑定到固定布局,您需要切换到dualIUnknown界面。只需按如下方式编辑您的AssemblyInfo.cs

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]
[assembly: ClassInterface(ClassInterfaceType.AutoDual)]

现在,接口的方法在类型库和智能感知中可见。

但请注意,对于AutoDual公开的类,在更新程序集时需要小心。有关详细信息,请参阅此链接。