I am currently working on a C# .NET Add-In for Microsoft Outlook. The goal of the Add-In is, to capture the search input from the Outlook Instant Search, and show in a Custom Pane my own search results.
It works pretty well, and with subclassing the Outlook Window with a Native Window, I get the search string, and it already passes that into my panel.
The problem is now, that when you close the Add-In (via "File->Options->Add-Ins->COM Add-Ins", but not with the X in the pane), the Add-In gets terminated instantly and I can't call searchboxWindow.ReleaseHandle()
beforehand to restore my WndProc chain. Outlook simply crashes without any visible errors.
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch ((uint)m.Msg)
{
case WindowMessages.WM_DESTROY:
case WindowMessages.WM_QUIT:
case WindowMessages.WM_NCDESTROY:
this.ReleaseHandle();
return;
case WindowMessages.WM_KEYUP:
case WindowMessages.WM_LBUTTONDOWN:
case WindowMessages.WM_RBUTTONDOWN:
OnKeyUp();
break;
case WindowMessages.WM_EXITSIZEMOVE:
OnResize();
break;
}
}
I already tried to listen to a few Window Messages that should be called when the Add-In gets closed, but these messages only appear when I close the Outlook in a normal way.
Also, the events in the main Add-In source file like AppDomain.CurrentDomain.ProcessExit
, this.Shutdown
, or ((Outlook.ApplicationEvents_10_Event)this.Application).Quit
don't get called.
What event can I listen on that (reliably) gets fired when the Add-In is terminated? Are there some? If not, what alternatives to solve my problem do I have?
SOLVED: Thanks to Hans Passant
It realy seems that the ThisAddIn_Shutdown
Event is triggered when the Add-In is manually disconnect through the COM Add-ins dialog box.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With