2008-10-24 85 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)