将.NET COM接口公开到VB6 [英] Exposing .NET COM Interfaces to VB6
问题描述
我正在看穆罕默德·穆萨·阿里(Muhammad Musa Ali)的文章,标题为为后期绑定公开.NET类库的COM接口".
我做了解决方案1,该解决方案是使用Visual Studio.NET的COM类模板创建一个COM对象.
因此,我有一个作为COM接口公开的.NET DLL,在同一解决方案中,我有一个.NET容器项目可以访问它. COM对象的目的是从app.config中获取连接字符串.我还添加了一个名为"Color"的属性,该属性返回一个简单的字符串以进行测试.
在.NET容器中,这两个属性均按预期工作,返回连接字符串和颜色.
当我在VB6中引用DLL时,color属性可以正常工作,但连接字符串属性因以下错误而失败:
I was looking at an article by Muhammad Musa Ali entitled "Exposing COM interfaces of a .NET class library for Late Binding"
I did Solution 1, which was to create a COM object using the COM class template of Visual Studio.NET.
So I have a .NET DLL that is exposed as a COM interface, and in the same solution I have a .NET container project that accesses it. The purpose of the COM object is to get a connection string out of app.config. I also added a property called "Color" that returns a simple string for testing purposes.
In the .NET container both properties work as expected returning the connection string and the color.
When I reference the DLL in VB6 the color property works fine but the connection string property fails with this error:
Overload resolution failed because no Public (Item) is most specific for these arguments:
''Public ReadOnly Property Item(index As Integer) As String'':
Not most specific.
''Public Property Item(name As String) As String'':
Not most specific.
我搜索了此错误,并且花了整整一天的时间来尝试解决此错误.如果您有什么想法会导致此,我将不胜感激任何建议.
谢谢,
Jerry
I googled this error and I''ve spent over a day trying to get this working. If you have any idea what might be causing this I would greatly appreciate any advice.
Thanks,
Jerry
推荐答案
我还在DLL中添加了一些日志记录.连接字符串名称正在传递给对象.
显然找不到app.config文件.我的app.config文件与VB6项目的测试文件位于同一目录中.
I also put some logging in the DLL. The connection string name is getting passed to the object.
It is apparently not finding the app.config file. I have the app.config file in the same directory as the test file for the VB6 project.
您确定要将VB6字符串传递给属性索引参数吗?它必须是一个字符串,它将解析为BSTR(COM中公开的.NET字符串).
Are you sure you are passing a VB6 string to the property index argument? It needs to be a string, which will resolve to a BSTR (which is what the .NET String is exposed as in COM).
这篇关于将.NET COM接口公开到VB6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!