【问题标题】:Passing an Enum To a COM Library method using Jacob使用 Jacob 将枚举传递给 COM 库方法
【发布时间】:2012-06-26 20:19:05
【问题描述】:

我实例化一个 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 中定义了一个枚举?

我需要以某种方式将枚举传递给方法,但我不知道如何访问它。

我尝试将 Enum 作为 ActiveXComponent,

new ActiveXComponent("MyDll.ReturnDeletedModeEnum");

其中(不足为奇)不起作用:

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

我尝试查找更多关于 Jacob 的文档,因为似乎有特定于 Enum 的类,但我没有找到任何关于如何使用它们的解释。

【问题讨论】:

    标签: java com activex jacob


    【解决方案1】:

    当我需要调用带有枚举参数的方法时,我遇到了同样的不确定性。我找不到太多文档 - 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));
    

    它成功了!

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

    【讨论】:

      猜你喜欢
      • 2011-09-09
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      • 2019-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多