[英]Native Window: Release Handle On Close
I am currently working on a C# .NET Add-In for Microsoft Outlook. 我目前正在为Microsoft Outlook开发C#.NET加载项。 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.
加载项的目标是从Outlook即时搜索中捕获搜索输入,并在自定义窗格中显示我自己的搜索结果。
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. 它运行得很好,并且通过使用本机窗口将Outlook窗口子类化,我得到了搜索字符串,它已经将它传递到我的面板中。
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. 现在的问题是,当您关闭加载项时(通过“ 文件 - >选项 - >加载项 - > COM加载项 ”,而不是窗格中的X),加载项立即终止我不能事先调用
searchboxWindow.ReleaseHandle()
来恢复我的WndProc链。 Outlook simply crashes without any visible errors. Outlook只是崩溃而没有任何明显的错误。
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. 我已经尝试收听一些应该在加载项关闭时调用的窗口消息,但这些消息仅在我以正常方式关闭Outlook时出现。
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. 此外,主要的加载项源文件中的事件,如
AppDomain.CurrentDomain.ProcessExit
, this.Shutdown
或((Outlook.ApplicationEvents_10_Event)this.Application).Quit
不会被调用。
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 解决:感谢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. 看起来,当通过COM加载项对话框手动断开加载项时,会触发
ThisAddIn_Shutdown
事件。
I don't think there is much you can do in the managed code. 我不认为您可以在托管代码中做很多事情。 Unmamaged code would have worked fine;
没有损坏的代码可以正常工作; the COM system would ask you politely whether your dll can be unloaded by calling your implementation of
DllCanUnload
. COM系统会通过调用你的
DllCanUnload
实现来礼貌地问你是否可以卸载你的dll。
确保在addin注册表中添加DWORD RequireShutdownNotification = 1,否则不会调用ThisAddIn_Shutdown()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.