最近在做一个项目,现在在java中需要调用matlab的dll,目前遇到的情况就是java通过jni调用vc++的dll,在vc++dll里面调用matlab的dll,知道到matlab dll里面的函数就报错了;错误如下:
"C:\Program Files\Java\jdk1.6.0_04\bin\javaw" -classpath "K:\CESHI\classes;C:\Program Files\Java\jdk1.6.0_04\sample\jnlp\servlet\jnlp-servlet.jar;C:\Program Files\Java\jdk1.6.0_04\sample\jnlp\servlet\jardiff.jar;C:\Program Files\Java\jdk1.6.0_04\sample\jnlp\servlet\jnlp.jar;C:\Program Files\Java\jdk1.6.0_04\lib\htmlconverter.jar;C:\Program Files\Java\jdk1.6.0_04\lib\tools.jar;C:\Program Files\Java\jdk1.6.0_04\lib\jconsole.jar;C:\Program Files\Java\jdk1.6.0_04\lib\dt.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\jce.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\im\indicim.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\im\thaiim.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.6.0_04\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0_04\demo\jfc\Java2D\Java2Demo.jar;C:\Program Files\Java\jdk1.6.0_04\demo\jfc\CodePointIM\CodePointIM.jar;C:\Program Files\Java\jdk1.6.0_04\demo\scripting\jconsole-plugin\jconsole-plugin.jar;C:\Program Files\Java\jdk1.6.0_04\demo\plugin\jfc\Java2D\Java2Demo.jar;C:\Program Files\Java\jdk1.6.0_04\demo\plugin\jfc\CodePointIM\CodePointIM.jar"  -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=USER-44F810BD23:3664,suspend=y CESHI ------------------------------------------------------------------------
        Fatal Java Exception detected at Wed Sep 10 20:39:19 2008
------------------------------------------------------------------------
Please follow these steps in reporting this problem to The MathWorks so
that we have the best chance of correcting it:    1. Send us this crash report.  For your convenience, this information
       has been recorded in: C:\DOCUME~1\user\LOCALS~1\Temp\java.log.3728    2. Provide a brief description of what you were doing when this
       problem occurred.    3. If possible, include M-files, MEX-files, or MDL-files that aid
       in reproducing it.    4. E-mail or FAX this information to us at:
                  E-mail:   [email protected]
                     FAX:   508-647-7201Thank you for your assistance.Opening log file:  C:\DOCUME~1\user\LOCALS~1\Temp\java.log.3728

解决方案 »

  1.   


    import com.jacob.activeX.ActiveXComponent;
    import com.jacob.com.ComThread;
    import com.jacob.com.Dispatch;
    import com.jacob.com.Variant;/**
     *<p>Title:</p>
     *<p>Description:</p>
     *@author Creator
     *@date 2008-9-11
     */
    public class DllTest {

    public void test() throws Exception {
    Variant ret = null;
    Dispatch dispatch = null;
    ActiveXComponent activeXComponent = null;
    try {
    ComThread.InitMTA();
    activeXComponent = new ActiveXComponent("ProgID");
    dispatch = activeXComponent.getObject();
    ret = Dispatch.call(dispatch, "method", "parameters");
    if(ret.getInt()!=0){
    throw new Exception("invoke fail");
    }
    } catch (Exception e) {
    throw new Exception(e);
    } finally{
    if (dispatch != null) {
    try {
    dispatch.safeRelease();
    } catch (Exception e) { } finally {
    dispatch = null;
    }
    }
    if (activeXComponent != null) {
    activeXComponent = null;
    }
    ComThread.Release();
    System.gc();
    }

    }
    }
      

  2.   


    import com.jacob.activeX.ActiveXComponent;
    import com.jacob.com.ComThread;
    import com.jacob.com.Dispatch;
    import com.jacob.com.Variant;/**
     *<p>Title:</p>
     *<p>Description:</p>
     *@author Creator
     *@date 2008-9-11
     */
    public class DllTest {

    public void test() throws Exception {
    Variant ret = null;
    Dispatch dispatch = null;
    ActiveXComponent activeXComponent = null;
    try {
    ComThread.InitMTA();
    activeXComponent = new ActiveXComponent("ProgID");
    dispatch = activeXComponent.getObject();
    ret = Dispatch.call(dispatch, "method", "parameters");
    if(ret.getInt()!=0){
    throw new Exception("invoke fail");
    }
    } catch (Exception e) {
    throw new Exception(e);
    } finally{
    if (dispatch != null) {
    try {
    dispatch.safeRelease();
    } catch (Exception e) { } finally {
    dispatch = null;
    }
    }
    if (activeXComponent != null) {
    activeXComponent = null;
    }
    ComThread.Release();
    System.gc();
    }

    }
    }
      

  3.   

    vc调用的时候没有问题,但是交给java的jni调用就无法调用到matlab里面的方法