gpt4 book ai didi

java - 使用 Jacob 将枚举传递给 COM 库方法

转载 作者:搜寻专家 更新时间:2023-11-01 03:54:52 25 4
gpt4 key购买 nike

我实例化一个 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

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

最佳答案

当我需要调用带有枚举参数的方法时,我遇到了同样的不确定性。我找不到太多文档 - JACOB 或其他。

我确实偶然发现了 helpful post on the subject其中表示 值 ... 对应于内部存储的数字VBA 中的枚举始终是 Long 数据类型

有了它和 MS Documentation for my particular Enumeration , 我试了一下 ...

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

成功了!

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

关于java - 使用 Jacob 将枚举传递给 COM 库方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11191674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com