2012-06-25 81 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,這正是我需要的! –