我使用c#编写了一个.NET程序集,以执行将由托管和非托管代码使用的函数。我有一个VB6项目,现在需要通过COM使用程序集。在VB6中引用.NET程序集将不起作用
我创建了我的.net程序集,确保ComVisible设置为true,并且它已通过项目属性注册为COM interop。
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
此外,intellesense不能在obj上工作。我必须输入GetResponse
方法。这是正常的吗?
有没有人有任何线索可能是错误的或我错过了什么步骤。谢谢!
工作就像一个魅力。非常感谢!我使用/ codebase命令运行regasm工具。/codebase也为你创建了tlb文件。感谢大家的回应。 – dretzlaff17 2010-06-08 19:25:24