2012-06-25 23 views
4

我實例化一個COM對象,然後調用一個方法。傳遞一個枚舉到一個使用Jacob的COM庫方法

ActiveXComponent comp = new ActiveXComponent("MyDll.MyClass"); 

String argument1 = "test1"; 
String argument2 = "test2"; 

Variant[] arguments = { new Variant(argument1), new Variant(argument2) }; 

comp.invoke("myMethod", arguments) 

假設MYDLL有一個名爲

myMethod(String s1, String s2) 

方法,它工作正常。

現在,如果我有什麼方法

myMethod(String s1, ReturnDeletedModeEnum enum) 

與MYDLL定義枚舉?

我需要以某種方式將枚舉傳遞給方法,但我不知道如何訪問它。

我試圖得到枚舉爲ActiveXComponent,

new ActiveXComponent("MyDll.ReturnDeletedModeEnum"); 

它(這並不奇怪)沒有工作:

com.jacob.com.ComFailException: Can't get object clsid from progid 

我試圖尋找關於雅各一些文檔,因爲似乎有枚舉特定的類,但我還沒有找到任何解釋如何使用它們。

回答

0

當我需要使用Enummeration參數調用方法時,遇到了相同的不確定性。我無法找到很多文檔 - JACOB或其他。

我確實碰到了helpful post on the subject,它說the values ... correspond to internally stored numbersAn enumeration in VBA is always of data type Long

武裝與和MS Documentation for my particular Enumeration,我給這是一個嘗試...

Dispatch.call(oDocuments, "Open", fileIn, ... , new Variant(1L)); 

和它的工作!

我確定有一種方法可以獲得實際的「枚舉」數據結構,但這對我來說足夠好。