4

我有一个用 c# 编写的 com dll 运行 Regasm 后,我可以从 VB6 调用这个 dll,引用 com dll。在 VB6 中,我可以使用智能感知。

但是,当我按 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
4

1 回答 1

1

上面我替换的接口声明

[InterfaceType(ComInterfaceType.InterfaceIsDual)]

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]

它解决了这个问题

于 2014-08-24T23:00:55.283 回答