【问题标题】:COM interop dictionary used in C#C# 中使用的 COM 互操作字典
【发布时间】:2012-06-26 21:23:57
【问题描述】:

我有一个第三方 DLL 我需要从我的 C# 程序中调用。

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

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

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

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

我尝试将其转换为 IDictionary、IDictionary、Hashtable 等等,但结果都相同……转换错误。 我猜这个 DLL 最初是用早期版本的 Visual Basic 编写的。

请帮忙...这个问题在过去两周里一直困扰着我...

问候 杰斯珀·桑加德

来自文档:

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 查看器):

[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);

【问题讨论】:

    标签: c# com dictionary vb6 interop


    【解决方案1】:

    如果我没记错的话,那就是旧 COM 运行时脚本库中的 Dictionary 对象:SCRRUN.dll 将 COM-TLB 导入您的项目并 强制转换您正在获取该类型的变体。

    【讨论】:

    • 谢谢@alexm,这正是我所需要的!
    猜你喜欢
    • 1970-01-01
    • 2010-12-14
    • 1970-01-01
    • 2014-09-05
    • 2014-09-03
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    • 2010-12-24
    相关资源
    最近更新 更多