2012-06-25 21 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)); 

和它的工作!

我确定有一种方法可以获得实际的“枚举”数据结构,但这对我来说足够好。