Skip to content

Commit 6cc15ad

Browse files
committed
Shortcut some WinEvent cases where the window is destroyed
1 parent 74b7bd9 commit 6cc15ad

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Source/ExcelDna.IntelliSense/UIMonitor/WinEvents.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,14 @@ void HandleWinEvent(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd,
189189
if (_hWndFilterOrZero != IntPtr.Zero && hWnd != _hWndFilterOrZero)
190190
return;
191191

192-
if (!IsSupportedWinEvent(eventType) || idObject == WinEventObjectId.OBJID_CURSOR)
192+
if (!IsSupportedWinEvent(eventType) || idObject == WinEventObjectId.OBJID_CURSOR || hWnd == IntPtr.Zero)
193193
return;
194194

195195
// Moving the GetClassName call here where the main thread is running.
196196
var windowClassName = Win32Helper.GetClassName(hWnd);
197+
198+
if (string.IsNullOrEmpty(windowClassName))
199+
return;
197200

198201
// CONSIDER: We might add some filtering here... maybe only interested in some of the window / event combinations
199202
_syncContextAuto.Post(OnWinEventReceived, new WinEventArgs(eventType, hWnd, windowClassName, idObject, idChild, dwEventThread, dwmsEventTime));

Source/ExcelDna.IntelliSense/Win32Helper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public static string GetClassName(IntPtr hWnd)
234234
// It failed!?
235235
int error = Marshal.GetLastWin32Error();
236236
Debug.Print($"GetClassName failed on {hWnd}(0x{hWnd:x}) - Error {error}");
237+
return "";
237238
}
238239
return _buffer.ToString();
239240
}

0 commit comments

Comments
 (0)