Hello,
some time ago I contacted you about a problem I had concerning message loops for COM components.
You suggested me, and you were right, to use a dedicated instance of OleMessageLoop for every instance of OleContainer I need.
The suggested code is as follows :
OleMessageLoop messageLoop = new OleMessageLoop(getClass().getName() + hashCode());
messageLoop.doStart();
_container = new OleContainer(messageLoop);
_container.createObject(ocxName);
add(_container, BorderLayout.CENTER);
Each container now receives only the messages that are sent to it.
I now try to register callbacks for each container that are instanciated using this method, and I get an exception c0000005.
The callbacks worked well before, but now, on the second attempt to register the callbacks, I get this exception.
Here is the class involved:
public class UserControl1Container extends JPanel implements UserControl1ContainerListener {
protected Frame frameParent;
protected OleContainer _container = null;
protected IConnectionPoint connectionPoint = null;
protected Int32 iHandler = null;
protected UserControl1Listener ocxListener = null;
public UserControl1Container(Frame frame) {
super();
frameParent = frame;
setBackground(Color.GRAY);
setPreferredSize(new Dimension(600, 400));
final BorderLayout layout = new BorderLayout();
this.setLayout(layout);
}
private void LoadActiveX(String ocxName) {
OleMessageLoop messageLoop = new OleMessageLoop(getClass().getName() + hashCode());
messageLoop.doStart();
_container = new OleContainer(messageLoop);
_container.createObject(ocxName);
add(_container, BorderLayout.CENTER);
}
public void active() {
_container.doVerb(OleVerbs.INPLACEACTIVATE);
}
private void setupListener()
{
IClassFactoryServer server = new IClassFactoryServer(UserControl1Listener.class);
server.registerInterface(IDispatch.class, new IDispatchVTBL(server));
server.registerInterface(__UserControl1.class, new IDispatchVTBL(server));
server.setDefaultInterface(IDispatch.class);
IClassFactory classFactory = server.createIClassFactory();
IDispatchImpl handler = new IDispatchImpl();
classFactory.createInstance(null, handler.getIID(), handler);
IOleObjectImpl oleObject = _container.getOleObject();
IConnectionPointContainer connectionPointContainer = new IConnectionPointContainerImpl(oleObject);
connectionPoint = connectionPointContainer.findConnectionPoint(new IID(__UserControl1.INTERFACE_IDENTIFIER));
IEnumConnections enumConnections = connectionPoint.enumConnections();
enumConnections.reset();
ocxListener = (UserControl1Listener)server.getInstances().pop();
ocxListener.setOCXPanel(this);
ocxListener.addContainerListener(this);
iHandler = connectionPoint.advise(handler);
}
public void FullLoad()
{
//this.setVisible(false);
LoadActiveX("OcxWithEchap.UserControl1");
OleMessageLoop.addAction(new Runnable()
{
public void run()
{
setupListener();
}
});
this.setVisible(true);
}
public void ocxClosed(EventObject e) {
connectionPoint.unadvise(iHandler);
_container.inPlaceDeactivate();
_container.destroyObject();
ocxListener.removeContainerListener(this);
this.setVisible(false);
}
public void myEvent1(EventObject e) {
System.out.println(" UserControl1Container");
System.out.println(" -
");
System.out.println(" myEvent1");
}
}
The exception occurs when this line of code is executed (in the setupListener method) :
IConnectionPointContainer connectionPointContainer = new IConnectionPointContainerImpl(oleObject);
The setupListerner method is called like this:
OleMessageLoop.addAction(new Runnable()
{
public void run()
{
setupListener();
}
});
Does the problem come from here, or....
Thanks for your help.
Pierre-Yves
PS: I attach the whole code to this message, in case you want to reproduce the problem.
- test.zip (19.5 K)