2012-06-25 153 views
0

我有我需要从我的C#程序调用的第三方DLL。C中使用COM互操作字典#

我已经将dll添加到了我的项目中的引用,并且VS2010已经生成了一个COM互操作封装器dll。 DLL中定义的接口和类现在可以在我的程序中使用,并可以按照他们的要求工作。

现在的问题是返回由整数和TSEnt对象的键值对组成的“字典”的方法。在DLL中,返回类型被定义为VARIANT *,在包装器中被定义为“object”。 DLL不包含任何字典界面。

我在C#中发现的唯一接口,我可以成功将此返回值转换为IEnumerable。但是使用foreach语句从返回值中获取值只会返回一个int32,它是基础键/值对的关键部分。

我如何获得这本词典的价值部分?

我试图将此类投射到IDictionary,IDictionary < int,object>,Hashtable等等,但所有都有相同的结果...投射错误。 我想DLL最初是用Visual Basic的早期版本编写的。

请帮助......这个问题已经困扰我在过去2周...

问候 加斯帕Sandgaard

从文档:

Query(String ObjectType, String PropName, String Pattern) 
Queries the repository for Objects of type ObjectType with the property PropName 
that have the value Pattern. Returns a Dictionary object containing a list of TSEnt 
objects that the repository returns. This list is keyed by the index of the elements 
in the list starting from 0. Pattern can contain ‘*’ as wildcard. If the Property 
name is a Domained value, use the Display Value in the repository model. 

从DLL(的ITypeLib Viewer):

[id(0x00000006), helpstring("method Query")] 
HRESULT Query(
[in] BSTR Type, 
[in] BSTR PropertyName, 
[in] BSTR Pattern, 
[out, retval] VARIANT* result); 

VS中的定义:

[DispId(6)] 
object Query(string Type, string PropertyName, string Pattern); 

回答

2

如果没记错的话这是从旧的COM运行脚本库Dictionary对象:SCRRUN.dll导入COM-TLB到你的项目和 投,你得到该类型的变体。

+0

感谢@alexm,这正是我需要的! –