如何在 Jcob 中使用 OCX 文件

How to use an OCX file in Jcob

我尝试通过 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 或其他东西。

您应该使用 createNewInstance 方法创建它,而不是创建新的 ActiveXComponent

    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");