您在C#中有一个项目,它使用方法GetArray()返回MyClass类型的对象列表。 我用regasm ClassLibrary1.dll / codebase / tlb注册这个dll,然后在VB6的项目中添加ClassLibrary1.tlb引用作为下面的代码。 当我在Microsoft Visual Studio 6.0中运行VB6应用程序时它可以工作,但是当我尝试运行vb6 exe时,我遇到运行时错误
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace ClassLibrary1
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("D878834C-306E-4260-905F-BDEBDF14CBDA")]
[ComVisible(true)]
public class MyProjectC
{
public MyClass[] GetArray()
{
var list = new List<MyClass>
{
new MyClass {Nome = "A"},
new MyClass {Nome = "AB"},
new MyClass {Nome = "AC2"},
new MyClass {Nome = "D"}
};
return list.ToArray();
}
}
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("D878834C-306E-4260-905F-BDEBDF14C111")]
[ComVisible(true)]
public class MyClass
{
public string Nome;
}
}
Private Sub Form_Load()
On Error GoTo error
Dim str As String
Dim oBookMark As Variant
Dim theProjectC As New ClassLibrary1.MyProjectC
For Each oBookMark In theProjectC.GetArray
str = oBookMark.Nome
MsgBox str
Next
Exit Sub
error:
MsgBox "Errore" & Err.Description
End Sub
答案 0 :(得分:0)
尝试将公共字段MyClass.Nome
更改为公共媒体资源:
public string MyNome { get; set; }