无法共同创建对象/找不到moniker |杰克 [英] Can't co-create object / Can't find moniker | Jacob

查看:884
本文介绍了无法共同创建对象/找不到moniker |杰克的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用JACOB创建 ActiveXComponent 时,得到以下错误。

When creating an ActiveXComponent using JACOB I get the following error.


com.jacob.com.ComFailException:无法共同创建对象
at com.jacob.com.Dispatch.createInstanceNative(本地方法)
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)

我需要使用来自不注册DLL的程序的COM对象

The COM object which I need to use from a program which doesn't register its DLLs by itself during installation.

要注册DLL根据文章,可以帮助。此外,我试图加载外部程序中的每个DLL,因为我怀疑加载依赖关系可能有东西错误。

To register the DLL I used the 64bit version of RegAsm according to this article that could help. Also, I tried to load every DLL in of the external program because I suspected that there could be "something" wrong with loading the dependencies.

这是我当前的代码:

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我有一个不同的异常。

When changing the name to the clsid I get a different exception.

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)

我让JACOB使用系统的Random对象在另一个测试中使用我的代码。

I got JACOB to work with my code in another test using the system's Random object.

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


推荐答案

我试过所有的解决方案,相关JACOB。按照以下示例代码创建代码。

I tried all solution and finally succeeded to crack the code related to JACOB. Create your code as per below sample code.

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。我也遵循你提到的同样的文章,但是当你处理applet不工作。

Now let me tell you how to register your DLL. I also followed same article you mentioned but not working when you are dealing with applet.

使用命令行转到 x86 框架。

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

注册do与

相同

不要传递除 / codebase 之外的任何其他标志。你完成了...仍然你发现任何问题让我知道...

Don't pass any other flag except /codebase. You are done with it... Still you find any problem let me know...

这篇关于无法共同创建对象/找不到moniker |杰克的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆