Search code examples
javaocx

How to use an OCX file in Jcob


I tried creating an ActiveXComponent object by clsid Like below:

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

but I get following exception:

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

I would be happy if someone could explain me what I'm doing wrong.

I have not done anything out of my program , such as registering any dll(s) or something.


Solution

  • Instead of creating a new ActiveXComponent you should create it by the createNewInstance method:

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