2017-05-25 73 views
5

我想從C#傳遞一個int列表到一個寫在vb6中的dll。在VB6的函數原型如下:無法從system.collections.generic.list轉換爲字符串到Vba.collections

Public Function FamIdentify(agentList As Collection, strName As String, strIdentifyTemplate As String, strIP As String) As Boolean 

從C#我調用這個函數如下:

public Boolean IdentifyFinger(String name, String SampleModel, String REMOTE_ADDR) 
{ 
List<int> agentList = new List<int>(); 
// insert some element to this list 
FamServer.FamApp famApp = new FamServer.FamApp(); 
Boolean flag = famApp.FamIdentify(ref agentList, ref name, SampleModel, REMOTE_ADDR); 
return flag ; 
} 

對於這種編碼,我面對這個錯誤

cannot convert from system.collections.generic.list to string to Vba.collections 

如何我可以通過列表從C#到VB6嗎?請幫幫我 。

+1

嘗試轉換爲'System.Collections.ArrayList'而不是 - 此類型可以通過'CreateObject()'方法暴露給VBA。 –

+0

您的評論對我而言並不清楚。你可以解釋嗎 ? –

+0

在C#中創建一個'ArrayList',用'List'的值填充它,在VBA代碼中創建'ArrayList',將'ArrayList'傳遞給VBA ... –

回答

2

您需要創建Microsoft.VisualBasic.Collection,從List添加值,然後才能將其傳遞到函數。我認爲,沒有直接投到Collection

Microsoft.VisualBasic.Collection agentCollection= new Microsoft.VisualBasic.Collection(); 
agentList.ForEach(x=> agentCollection.Add(x)); 

Boolean flag = famApp.FamIdentify(ref agentCollection, ref name, SampleModel, REMOTE_ADDR); 
+0

名稱空間'Collection'的類型在名稱空間'Microsoft.VisualBasic'中不存在。 (您是否缺少程序集引用?) –

+0

'C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework \ .NETFramework \ v4.5.2 \ Microsoft.VisualBasic.dll'或類似的地方 –

+0

無法從Microsoft轉換。 VisualBasic.Collection到VBA.Collection。 –

相關問題