2

我创建了一个 .NET DLL,它使一些方法 COM 可见。

一种方法是有问题的。它看起来像这样:

bool Foo(byte[] a, ref byte[] b, string c, ref string d)

当我尝试调用该方法时,VB6 给出了一个编译错误:

标记为受限的函数或接口,或函数使用 Visual Basic 不支持的自动化类型。

我读到数组参数必须通过引用传递,所以我更改了签名中的第一个参数:

bool Foo(ref byte[] a, ref byte[] b, string c, ref string d)

VB6 仍然给出相同的编译错误。

如何更改签名以与 VB6 兼容?

4

3 回答 3

6

需要用“ref”声明数组参数。您的第二次尝试应该工作得很好,也许您忘记重新生成 .tlb?

测试代码:

[ComVisible(true)]
public interface IMyInterface {
 bool Foo(ref byte[] a, ref byte[] b,string c, ref string d);
}

[ComVisible(true)]
public class MyClass : IMyInterface {
  public bool Foo(ref byte[] a, ref byte[] b, string c, ref string d) {
    throw new NotImplementedException();
  }
}


  Dim obj As ClassLibrary10.IMyInterface
  Set obj = New ClassLibrary10.MyClass
  Dim binp() As Byte
  Dim bout() As Byte
  Dim sinp As String
  Dim sout As String
  Dim retval As Boolean
  retval = obj.Foo(binp, bout, sinp, sout)
于 2008-10-24T13:15:12.570 回答
1

尝试

[ComVisible(true)]
bool Foo([In] ref byte[] a, [In] ref byte[] b, string c, ref string d)
于 2008-10-24T13:05:34.353 回答
1

与此相关的事情是我的问题。我在 C# 中有一个具有以下签名的方法:

public long ProcessWiWalletTransaction(ref IWiWalletTransaction wiWalletTransaction)

VB 6 不断抱怨“功能或接口标记为受限......”,我认为这是我在调用中使用的自定义对象。原来 VB 6 做不到,不得不将签名更改为:

public int ProcessWiWalletTransaction(ref IWiWalletTransaction wiWalletTransaction)
于 2009-10-05T09:23:18.237 回答