JAVA中如何调用VC的OCX?最好能有个例子!!!!

解决方案 »

  1.   

    可以利用jni调用或者利用微软提供的J/Direct直接调用win32dll,利用@dll.import引入如果要调用com组件的话要利用jactivex将com生成java源码
    然后利用ms的jvm进行编译即可引用(用了@com指令)think in java 的附录A里有,非常详细
    可以试试COM-Java的桥接!
    如J-Integra,支持COM和Java组件的双向通信而且不需要本机库!
    另外可以关注一下J2EE的COM桥(好像是叫CAS吧)!
      

  2.   

    你提的这个问题可够大的。很多公司或组织都有相关的产品。
    你想用JNI实现一遍,几乎是不可能完成的任务。
    对象的控制、方法的控制、事件的控制、GUI控制,复杂的很。
    我自己用JNI实现了对托盘的控制,感觉就够复杂的了。(除了Windows API外,不同Windows版本的兼容性还的考虑,累),对Com的完整控制就更复杂多了。
    听masse的吧,看看第三方的东西,会有收获。
      

  3.   

    我用过JNI,但是这个需要修改VC的代码,现在OCX已经定死了所以想其他的办法,看到JAWIN好象还可以,但是出现异常,大家有用过的看一看org.jawin.COMException: 8000ffff: NULL GIT peer
    at org.jawin.marshal.GenericStub.dispatchInvoke0(Native Method)
    at org.jawin.marshal.GenericStub.dispatchInvoke(GenericStub.java:201)
    at org.jawin.DispatchPtr.invokeN(DispatchPtr.java:587)
    at org.jawin.DispatchPtr.invokeN(DispatchPtr.java:555)
    at test3._DGisSeat.OcxTest(_DGisSeat.java:231)
    at test3.Test.<init>(Test.java:38)
    at test3.Test.main(Test.java:45)
    Exception in thread "main" 
    调用过的两个类:/*
     * 创建日期 2005-8-1
     *
     * TODO 要更改此生成的文件的模板,请转至
     * 窗口 - 首选项 - Java - 代码样式 - 代码模板
     */
    package test3;import org.jawin.COMException;
    import org.jawin.DispatchPtr;/**
     * @author user
     *
     * TODO 要更改此生成的类型注释的模板,请转至
     * 窗口 - 首选项 - Java - 代码样式 - 代码模板
     */
    public class Test
    {
        public Test() throws COMException
        {
            
            _DGisSeat d = new _DGisSeat();
            
            short i = d.OcxTest();
            
            System.out.println( i + "              iiiiii");
        }
        
        public static void main( String []args) throws COMException
        {
            Test t = new Test();
        }
    }package test3;import org.jawin.*;import org.jawin.constants.*;import org.jawin.marshal.*;import org.jawin.io.*;import java.io.*;import java.util.Date;/** * Jawin generated code please do not edit * * Dispatch: _DGisSeat * Description: Dispatch interface for GisSeat Control * Help file:   C:\WINNT\system32\GisSeat.hlp * * @author JawinTypeBrowser */public class _DGisSeat extends DispatchPtr { public static final GUID DIID = new GUID("{854de4f8-61da-4465-93A9-23E9734351F8}"); public static final int IID_TOKEN; static { IID_TOKEN = IdentityManager.registerProxy(DIID, _DGisSeat.class); } /**  * The required public no arg constructor.  * <br><br>  * <b>Important:</b>Should never be used as this creates an uninitialized  * _DGisSeat (it is required by Jawin for some internal working though).  */ public _DGisSeat() { super(); } /**  * For creating a new COM-object with the given progid and with   * the _DGisSeat interface.  *   * @param progid the progid of the COM-object to create.  */ public _DGisSeat(String progid) throws COMException { super(progid, DIID); } /**  * For creating a new COM-object with the given clsid and with   * the _DGisSeat interface.  *   * @param clsid the GUID of the COM-object to create.  */ public _DGisSeat(GUID clsid) throws COMException { super(clsid, DIID); } /**  * For getting the _DGisSeat interface on an existing COM-object.  * This is an alternative to calling {@link #queryInterface(Class)}  * on comObject.  *   * @param comObject the COM-object to get the _DGisSeat interface on.  */ public _DGisSeat(COMPtr comObject) throws COMException { super(comObject); } public int getIIDToken() { return IID_TOKEN; }     /**    *        * @return int    **/    public int InitSocket() throws COMException    {       return ((Integer)invokeN("InitSocket", new Object[] {})).intValue();            }    /**    *        * @param strSendInfo    * @return int    **/    public int SendInfo(String strSendInfo) throws COMException    {       return ((Integer)invokeN("SendInfo", new Object[] {strSendInfo})).intValue();            }    /**    *        * @return int    **/    public int CloseSocket() throws COMException    {       return ((Integer)invokeN("CloseSocket", new Object[] {})).intValue();            }    /**    *        * @return short    **/    public short OcxTest() throws COMException    {       return ((Short)invokeN("OcxTest", new Object[] {})).shortValue();            }    /**    *        * @return void    **/    public void AboutBox() throws COMException    {       invokeN("AboutBox", new Object[] {});            }}