INTERACT FORUM

Windows => Plug-in Development => Topic started by: apranger on July 06, 2002, 08:32:04 am

Title: What happens when MJ closes?
Post by: apranger on July 06, 2002, 08:32:04 am
What happens when MJ closes, or exits, etc?

Do MJ plugins recieve any sort of event or message that can be handled?  Web Remote keeps some socket connections open (in ziggraut's modified version), and we have to close them before MJ goes away to prevent a crash on exit.

Adam
Title: RE:What happens when MJ closes?
Post by: Nikolay on July 08, 2002, 11:30:34 am
Plug-in can do clean up two ways:
1. implement OnFinalRelease function, I think it works only in MFC.
2. implement Terminate function (void Terminate(void)), the function implementation is similar to Init function.

Nikolay
Title: RE:What happens when MJ closes?
Post by: zigguratt on July 08, 2002, 12:02:52 pm
On a quick first attempt the function doesn't seem to be called.

I added

void CWebRemoteCtrl::Terminate(void)
{
   m_HTTPServer.StopServer();
}

just after the definition of Init() in WebRemoteCtrl.cpp and added "void Terminate(void);" in the .h file just after the Init line as well. To prove it wasn't called, I put an infinite loop in Terminate() so I could see everything freeze. It didn't.
Title: RE:What happens when MJ closes?
Post by: Nikolay on July 08, 2002, 01:00:26 pm
I fogot to mention, but Terminate function must be implemented as COM function. For that you need to modify 3 files:

WebRemote.idl:
interface IWebRemoteCtrl : IDispatch
{
 [id(1), helpstring("method Init")] HRESULT Init([in] LPDISPATCH pDisp);
[id(2), helpstring("method Terminate")] HRESULT Terminate(); };

WebRemoteCtrl.cpp:

STDMETHODIMP CWebRemoteCtrl::Terminate()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())

...

return S_OK;
}

WebRemoteCtrl.cpp:
STDMETHOD(Terminate)();

Nikolay
Title: RE:What happens when MJ closes?
Post by: zigguratt on July 08, 2002, 04:26:04 pm
Thanks Nikolay, I've added the code as you specified above and all compiles properly. Now I just have to figure out how to keep track of the sockets that are open and close them all on termination.