【发布时间】:2011-03-01 07:41:20
【问题描述】:
我使用 c# 编写了一个 .net 程序集来执行托管和非托管代码都将使用的功能。我有一个 VB6 项目,现在需要通过 COM 使用程序集。
我创建了我的 .net 程序集,确保 ComVisible 设置为 true 并通过项目属性为 COM 互操作注册。
public class MyClass
[ComVisible(true)]
public string GetResponse()
{
return "Testing Response"
}
}
我构建了程序集并将文件复制到一个文件夹中。 TestInterop.dll
然后我运行一个批处理文件来注册组装工具来为 COM 注册对象。
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319\
regasm "c:\Program Files\TestApp\TestInterop.dll" /tlb:TestInterop.tlb
我打开一个新的 VB6 应用程序并引用 TestInterop.dll
在 VB6 中,我编写了以下代码并编译。
Dim obj as TestInterop.MyClass
Set obj = new TestInterop.MyClass
Dim strTest as string
strTest = obj.GetRespose()
当我运行程序时,它在 obj.GetResponse() 行上出错。
Run-time error' -2147024894 (80070002'):
Automation error
The system cannot find the file specified
此外,智能感知不适用于 obj。我必须输入GetResponse 方法。这正常吗?
有没有人知道可能出了什么问题或我错过了哪些步骤。谢谢!
【问题讨论】: