我有一个用c#编写的com dll
运行Regasm之后
我可以从VB6调用这个dll,引用com dll.
在VB6中我有intellisense可用.
运行Regasm之后
我可以从VB6调用这个dll,引用com dll.
在VB6中我有intellisense可用.
但是,当我按F5编译时,编译器不会在调用com dll时发现任何错误.它必须使用后期绑定.
如何让它使用早期绑定?
声明了接口
using System.Runtime.InteropServices; namespace combridge { [Guid("2f4b6041-91e3-4d9f-a9f5-9bd4adfd1789")] [ComVisible(true)] [InterfaceType(ComInterfaceType.InterfaceIsDual)] public interface IBridge { // methods go here } }
宣布主要类
[Guid("085777fa-9397-4cfd-843a-85ececb86789")] [ProgId("companyname.ComBridge")] [ClassInterface(ClassInterfaceType.None)] [ComVisible(true)] public class BridgeImplementation : IBridge { #region Public Implementation [DispId(1)] [ComVisible(true)] public string EchoTest(string message) { return string.Format("Echo '{0}' at {1:T}",message,DateTime.Now); } // etc
[更新]
在VB6项目中,我引用了我创建的tlb文件
c:\WINDOWS\Microsoft.Net\Framework\v4.0.30319/regasm /verbose /codebase /tlb:CommBridge.tlb ComBridge.dll
在VB6中我使用创建对象
Dim o As BridgeImplementation Set o = New BridgeImplementation o.EchoTest // executes o.NonExistantFunction // run time error
解决方法
在接口声明之上
我换了
我换了
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
同
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
它解决了这个问题