gpt4 book ai didi

.net - 强制 VB6 编译器在调用 .net com dll 时使用早期绑定(bind)

转载 作者:行者123 更新时间:2023-12-02 06:19:12 24 4
gpt4 key购买 nike

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

但是,当我按 F5 编译时,编译器在调用 com dll 时没有发现任何错误。它必须使用后期绑定(bind)。

如何让它使用早期绑定(bind)?

接口(interface)已声明

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

最佳答案

接口(interface)声明上方我更换了

[InterfaceType(ComInterfaceType.InterfaceIsDual)]

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]

问题解决了

关于.net - 强制 VB6 编译器在调用 .net com dll 时使用早期绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25469968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com