如何在Jcob中使用OCX文件

时间:2018-07-21 08:01:39

标签: java ocx

我尝试通过clsid创建ActiveXComponent对象,如下所示:

public static void main(String[] args) {
    System.setProperty(LibraryLoader.JACOB_DLL_PATH, "C:\\Users\\TelC\\Downloads\\jacob-1.19\\jacob-1.19-x64.dll");
    LibraryLoader.loadJacobLibrary();
    ActiveXComponent comp=new ActiveXComponent("clsid:5B769435-52C8-11D2-B347-444553540000");
    System.out.println("The Library been loaded, and an activeX component been created");
}

但是我得到以下异常:

com.jacob.com.ComFailException: Can't find moniker

如果有人可以向我解释我在做什么错,我会很高兴。

我还没有做任何事情,例如注册任何dll或其他东西。

1 个答案:

答案 0 :(得分:1)

您应该通过ActiveXComponent方法来创建它,而不是创建一个新的createNewInstance

    System.setProperty(LibraryLoader.JACOB_DLL_PATH, "C:\\Users\\TelC\\Downloads\\jacob-1.19\\jacob-1.19-x64.dll");
    LibraryLoader.loadJacobLibrary();
    ActiveXComponent comp=ActiveXComponent.createNewInstance("clsid:5B769435-52C8-11D2-B347-444553540000");
    System.out.println("The Library been loaded, and an activeX component been created");