@@ -26,7 +26,8 @@ public sealed class ShellPreviewViewModel : BasePreviewModel
2626 {
2727 PreviewHandler ? currentHandler ;
2828 ContentExternalOutputLink ? outputLink ;
29- WNDCLASSEXW ? wCls ;
29+ WNDCLASSEXW _windowClass ;
30+ WNDPROC _windProc = default ;
3031 HWND hwnd = HWND . Null ;
3132 bool isOfficePreview = false ;
3233
@@ -123,10 +124,11 @@ public unsafe void LoadPreview(UIElement presenter)
123124
124125 fixed ( char * pszClassName = szClassName )
125126 {
126- var pWindProc = Marshal . GetFunctionPointerForDelegate ( WndProc ) ;
127+ _windProc = new ( WndProc ) ;
128+ var pWindProc = Marshal . GetFunctionPointerForDelegate ( _windProc ) ;
127129 var pfnWndProc = ( delegate * unmanaged[ Stdcall] < HWND , uint , WPARAM , LPARAM , LRESULT > ) pWindProc ;
128130
129- wCls = new WNDCLASSEXW
131+ _windowClass = new WNDCLASSEXW ( )
130132 {
131133 cbSize = ( uint ) Marshal . SizeOf ( typeof ( WNDCLASSEXW ) ) ,
132134 lpfnWndProc = pfnWndProc ,
@@ -142,6 +144,8 @@ public unsafe void LoadPreview(UIElement presenter)
142144 cbWndExtra = 0 ,
143145 } ;
144146
147+ PInvoke . RegisterClassEx ( _windowClass ) ;
148+
145149 fixed ( char * pszWindowName = szWindowName )
146150 {
147151 hwnd = PInvoke . CreateWindowEx (
@@ -244,8 +248,7 @@ public void UnloadPreview()
244248 //outputLink?.Dispose();
245249 outputLink = null ;
246250
247- if ( wCls is not null )
248- PInvoke . UnregisterClass ( wCls . Value . lpszClassName , PInvoke . GetModuleHandle ( default ( PWSTR ) ) ) ;
251+ PInvoke . UnregisterClass ( _windowClass . lpszClassName , PInvoke . GetModuleHandle ( default ( PWSTR ) ) ) ;
249252 }
250253
251254 public unsafe void PointerEntered ( bool onPreview )
0 commit comments