4 Replies Last post: Aug 14, 2008 10:17 AM by Manuel Crespo  
Manuel Crespo   12 posts since
Apr 24, 2006
Currently Being Moderated

Aug 7, 2008 5:04 PM

Exception when closing Java application

Hello,

 

I'm just starting to use ComfyJ, so probably I'm not doing something right.

 

I have created an ActiveForm with Delphi. I'm able to embeb it inside a Delphi form and even I can call its events and everything works fine. The problem is when I close my java container application. It crash, I get this:

 

Exception eedfade, at 7C812A5B

Native function stack data: b6d224c,393748,11,21

 

I have tested the same with another ActiveX and I get this other error:

 

Exception c0000005, at 10001B67

Access violation: attempting to read memory at address 0B66976C

 

 

I copy the code of my test application:

 


package pruebamanolo.mainproject;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;
import com.jniwrapper.win32.automation.OleContainer;
import com.jniwrapper.win32.com.types.CLSID;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.jniwrapper.win32.ole.types.OleVerbs;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.jniwrapper.Int32;
import com.jniwrapper.win32.ole.OleFunctions;
import pruebamanolo.manoloactiveformproj1.IManoloActiveForm;
import pruebamanolo.manoloactiveformproj1.impl.IManoloActiveFormImpl;

public class Frame3 extends JFrame {
    OleContainer _container = new OleContainer();
    IManoloActiveForm manoloActiveForm;
    
    JPanel contentPane;
    BorderLayout borderLayout1 = new BorderLayout();

    public static final CLSID CLASS_ID = CLSID.create("{10697673-62BC-4CBA-A63F-5D56145C2D3C}");
    JPanel jPanel1 = new JPanel();
    JButton jButton1 = new JButton();

    public Frame3() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    /**
     * Component initialization.
     *
     * @throws java.lang.Exception
     */
    private void jbInit() throws Exception {
        OleFunctions.oleInitialize();
        
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(borderLayout1);
        setSize(new Dimension(800, 600));
        setTitle("Prueba ActiveX");
        jButton1.setText("Cambio de color");
        jButton1.addActionListener(new Frame3_jButton1_actionAdapter(this));
        contentPane.add(jPanel1, java.awt.BorderLayout.SOUTH);
        jPanel1.add(jButton1);
        inicializa();
    }

    private void inicializa() {
        getContentPane().add(_container, BorderLayout.CENTER);
        createOleObject();
        addWindowListener(new WindowAdapter()
        {
            public void windowOpened(WindowEvent e)
            {
                showOleObject();
            }

            public void windowClosing(WindowEvent e)
            {
                destroyOleObject();
            }
        });
    }


    private void createOleObject()
    {
        _container.createObject(CLASS_ID);    
        manoloActiveForm = new IManoloActiveFormImpl(_container.getOleObject());
        
    }

    private void showOleObject()
    {
        _container.doVerb(OleVerbs.SHOW);
    }

    private void destroyOleObject()
    {
        _container.destroyObject();
        OleFunctions.oleUninitialize();
    }

    private void cambioDeColor() {
        Int32 r = new Int32(0);
        Int32 g = new Int32(0);
        Int32 b = new Int32(0);

        manoloActiveForm.cambioDeColor(r,g,b);
    }

    public void jButton1_actionPerformed(ActionEvent e) {
        cambioDeColor();
    }


}


class Frame3_jButton1_actionAdapter implements ActionListener {
    private Frame3 adaptee;
    Frame3_jButton1_actionAdapter(Frame3 adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}

 

 

Thanks

Manuel Crespo

Igor Novikov TeamDev Ltd. 225 posts since
Apr 24, 2006
Currently Being Moderated
1. Aug 12, 2008 4:26 PM in response to: Manuel Crespo
Re: Exception when closing Java application

Hi Manuel,

 

We have tested your sample using MS Excel object as an ActiveX substitution and found that sample works correctly. In attachment you can find slightly modified Frame3 class. So I can suppose that problem is on native side or in generated wrappers for your component.

 

 

 

Can you provide us your ActiveX component and generated wrappers to verify problem source? For security reason you can mail it on our support e-mai:  comfyj-support (at) teamdev.com.

 

 

 

Sincerely,

 

 

 

Igor Novikov

Attachments:
Igor Novikov TeamDev Ltd. 225 posts since
Apr 24, 2006
Currently Being Moderated
3. Aug 13, 2008 9:47 PM in response to: Manuel Crespo
Re: Exception when closing Java application

Hi Manuel,

 

We have reproduced this issue using ComfyJ 2.4 library. The problem cause is unreleased native resource.

To fix this issue you can try using latest ComfyJ build which can be downloaded on following link:

 

ftp://ftp.teamdev.com/updates/comfyj-2.4.902.zip

 

In our tests the problem is not reproducible for this build because it contains some fixes for native resource management.

 

But in your code only one COM interface is used. Therefore for such simplified use-case build-in Native Resource Collector works correctly. For complex COM interfaces you need disabling automatic release for instantiated object and manage them manually. As an example please take a look at ExcelIntegrationSample.java class in ComfyJ package samples. In the sample each instantiated interface is marked by markAutoDelete() after instantiation and released by release() method after usage. Only such management of native COM resources can provide correct releasing and successful termination of application.

 

Please try these suggestions and let us known the results.

 

Sincerely,

 

Igor Novikov

 

P.S. Unfortunately we cannot send you this message by e-mail due to some email issues. So we publish it on the support forum.

More Like This

  • Retrieving data ...