Не удается совместно создать объект / Не удается найти прозвище | Джейкоб

При создании ActiveXComponent с помощью JACOB я получаю следующую ошибку.

com.jacob.com.ComFailException: Can't co-create object
    at com.jacob.com.Dispatch.createInstanceNative(Native Method)
    at com.jacob.com.Dispatch.<init>(Dispatch.java:99)
    at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58)
    at com.paston.jacobtest.RidderIQ.main(RidderIQ.java:30)

COM-объект, который мне нужно использовать из программы, которая сама не регистрирует свои библиотеки DLL во время установки.

Для регистрации DLL я использовал 64-битную версию RegAsm согласно эта статья, которая может помочь. Кроме того, я пытался загрузить каждую DLL из внешней программы, потому что подозревал, что с загрузкой зависимостей может быть «что-то» не так.

Вот мой текущий код:

public static void main(String[] args) {

    String dllDir = "C:\\Program Files (x86)\\Ridder iQ Client\\Bin\\";
    File folder = new File( dllDir );

    for (final File fileEntry : folder.listFiles()) {
        String str = fileEntry.getName();
        if (str.substring(str.lastIndexOf('.') + 1).equals("dll")) {
            System.out.println(fileEntry.getName());
            System.load(dllDir + str);
        }
    }

    try {
        ActiveXComponent example = new ActiveXComponent("RidderIQSDK");
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }

}

При изменении имени на clsid я получаю другое исключение.

com.jacob.com.ComFailException: Can't find moniker
at com.jacob.com.Dispatch.createInstanceNative(Native Method)
at com.jacob.com.Dispatch.<init>(Dispatch.java:99)
at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58)
at com.paston.jacobtest.RidderIQ.main(RidderIQ.java:28)

Я попросил ЯКОБА поработать с моим кодом в другом тесте, используя системный объект Random.

    ActiveXComponent random = new ActiveXComponent("clsid:4E77EC8F-51D8-386C-85FE-7DC931B7A8E7");
    Object obj = random.getObject();

    Object result = Dispatch.call((Dispatch) obj, "Next");
    System.out.println("Result: "+result);

person Roel Veldhuizen    schedule 22.04.2013    source источник


Ответы (1)


Я попробовал все решения и, наконец, мне удалось взломать код, связанный с JACOB. Создайте свой код в соответствии с приведенным ниже образцом кода.

public static void main(String[] args) {
        String libFile = System.getProperty("os.arch").equals("amd64") ? "jacob-1.17-x64.dll" :"jacob-1.17-x86.dll";
        try{
            /**
             * Reading jacob.dll file
             */
            InputStream inputStream = certificatemain.class.getResourceAsStream(libFile);
            /**
             *  Step 1: Create temporary file under <%user.home%>\AppData\Local\Temp\jacob.dll 
             *  Step 2: Write contents of `inputStream` to that temporary file.
             */
            File temporaryDll = File.createTempFile("jacob", ".dll");
            FileOutputStream outputStream = new FileOutputStream(temporaryDll);
            byte[] array = new byte[8192];
            for (int i = inputStream.read(array); i != -1; i = inputStream.read(array)){
                outputStream.write(array, 0, i);
            }
            outputStream.close();
            /* Temporary file will be removed after terminating-closing-ending the application-program */
            System.setProperty(LibraryLoader.JACOB_DLL_PATH, temporaryDll.getAbsolutePath());
            LibraryLoader.loadJacobLibrary();

            ActiveXComponent comp=new ActiveXComponent("Com.Calculation");        
            System.out.println("The Library been loaded, and an activeX component been created");

            int arg1=100;
            int arg2=50;
            //using the functions from the library:        
            int summation=Dispatch.call(comp, "sum",arg1,arg2).toInt();
            System.out.println("Summation= "+ summation);
        }catch(Exception e){
            e.printStackTrace();
        }
}

Теперь позвольте мне рассказать вам, как зарегистрировать вашу DLL. Я также следил за той же статьей, которую вы упомянули, но не работал, когда вы имеете дело с апплетом.

Перейдите в x86 framework с помощью командной строки.

C:\Windows\Microsoft.NET\Framework\v2.0.50727

чтобы зарегистрироваться сделать то же самое, что и

regasm.exe path_to_your_dll.dll /codebase

Не передавайте никакой другой флаг, кроме /codebase. Вы закончили с этим... Тем не менее, вы обнаружите какие-либо проблемы, дайте мне знать...

person Vicky Thakor    schedule 30.08.2013