Native window: release descriptor

I am currently working on a C # .NET add-in for Microsoft Outlook. The purpose of the add-in is to capture the search obtained from Outlook Instant Search and display your own search results in custom panels.

This works very well, and with the subclassing of the Outlook window using my own window, I get a search string, and it already passes it to my panel.

The problem is that when you close the add-in (via "File-> Options-> Add-Ins-> COM Add-Ins", but not from the X to the panel), the add-in ends instantly and I cannot call searchboxWindow.ReleaseHandle() in advance to restore the WndProc chain. Outlook just crashes without 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 have already tried to listen to several window messages that should be called when the add-in closes, but these messages appear only when Outlook closes in the usual way.

In addition, events in the main Add-In source file such as AppDomain.CurrentDomain.ProcessExit , this.Shutdown or ((Outlook.ApplicationEvents_10_Event)this.Application).Quit not called.

In what event can I listen (reliably) when the add-in starts? There are some? If not, what alternatives do I have to solve my problem?

+7
c # outlook wndproc outlook-addin
source share
3 answers

SOLVED: Thanks to Hans Passant

It seems that the ThisAddIn_Shutdown event is ThisAddIn_Shutdown when the add-in is manually disabled through the COM add-ins dialog.

+1
source share

I don’t think that you can do much in managed code. Not corrupted code would work fine; the COM system will ask you politely if your DLL can be unloaded by invoking your DllCanUnload implementation.

0
source share

Make sure you add DWORD RequireShutdownNotification = 1 to the add-in registry, otherwise ThisAddIn_Shutdown () will not be called

0
source share

All Articles