2008-10-24 92 views
2

我创建了一个.NET DLL,它使一些方法COM可见。从VB6通过COM调用.NET方法可见DLL

一种方法存在问题。它看起来像这样:

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兼容?

回答

5

声明数组参数与 “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) 
+0

是的我忘了重新生成.tlb了,谢谢! 由于我不再直接提到VB6机器上的.tlb,我还没有意识到它仍在使用中。 – 2008-10-24 16:13:02

1

尝试

[ComVisible(true)] 
bool Foo([In] ref byte[] a, [In] ref byte[] b, string c, ref string d) 
1

东西有关,这是我的问题。我在C#具有以下签名的方法:

public long ProcessWiWalletTransaction(ref IWiWalletTransaction wiWalletTransaction) 

VB 6劲儿抱怨“函数或接口标记为受限制......”,我以为这是我的电话使用我的自定义对象。原来VB 6做不了多久,只好把签名改成:

public int ProcessWiWalletTransaction(ref IWiWalletTransaction wiWalletTransaction)