diff --git a/ThePBone.Interop.Win32/WndProcClient.cs b/ThePBone.Interop.Win32/WndProcClient.cs index d6143e3be..e23082657 100644 --- a/ThePBone.Interop.Win32/WndProcClient.cs +++ b/ThePBone.Interop.Win32/WndProcClient.cs @@ -12,11 +12,13 @@ public partial class WndProcClient public event EventHandler? MessageReceived; private readonly IntPtr _hwnd; + /* prevent garbage collection */ + private readonly Unmanaged.WNDCLASSEX _wndClassEx; public IntPtr WindowHandle => _hwnd; public WndProcClient() { - Unmanaged.WNDCLASSEX wndClassEx = new Unmanaged.WNDCLASSEX + _wndClassEx = new Unmanaged.WNDCLASSEX { cbSize = Marshal.SizeOf(), lpfnWndProc = delegate(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { @@ -36,7 +38,7 @@ public WndProcClient() lpszClassName = "MessageWindow " + Guid.NewGuid(), }; - ushort atom = Unmanaged.RegisterClassEx(ref wndClassEx); + ushort atom = Unmanaged.RegisterClassEx(ref _wndClassEx); if (atom == 0) {