我如何可以通过从VB6对象的集合到.NET?可以通过、对象、NET

2023-09-05 23:54:38 作者:继续我的辉煌

我需要传递键/值对字符串的集合从VB6到.NET。在VB6 code它们存在于本地集合。但我不知道我可以在我的.NET项目引用要能接受我的方法之一类型集合的参数。

I need to pass a collection of key/value pairs of strings from VB6 to .NET. In VB6 code they exist in a native collection. But I am not sure what I can reference in my .NET project to be able to accept a parameter of type Collection in one of my methods.

我尝试添加引用Visual Basic应用程序,但回来一提到'Visual Basic应用程序不能添加。

I tried adding a reference to Visual Basic for Applications but got back "A reference to 'Visual Basic For Applications' could not be added."

我要对错误的方式?

推荐答案

您可以使用这样的事情在C#:

You could use something like this in c#:

[Guid("fb5e929a-2f8b-481e-9516-97edf5099df4")]
[ComVisible(true)]
public interface myInterface{
public void addObject(string key, string value);
}

而在你的类,你可以有这样的:

And in your class, you could have this:

private collection
public addObject(string key, string value)
{
collection.Add(key, value);
}

这应该允许您呼叫ADDOBJECT在VB6和传递您的数据。那么.NET将它添加到集合,所以不是通过你的整个收藏从VB6到.NET,你把它们一个接一个。

This should allow you to call addObject in vb6 and passing your data. Then .net will add it to a collection, so instead of passing your whole collection from vb6 to .net, you pass them one by one.

您可以阅读更多有关 GUID这里

有关COM与code VB6之间的为例更多信息在这里C#。

More info about COM with an exemple of code between vb6 and c# here.