@@ -22,8 +22,8 @@ public unsafe partial class WindowsFolderWatcher : IFolderWatcher
22
22
private const uint WM_FOLDERWATCHER = PInvoke . WM_APP | 0x0001U ;
23
23
private readonly WNDPROC _wndProc ;
24
24
25
- private uint _registrationID = 0U ;
26
- private ITEMIDLIST * _pidl = default ;
25
+ private uint _watcherRegID = 0U ;
26
+ private ITEMIDLIST * _targetItemPIDL = default ;
27
27
28
28
// Properties
29
29
@@ -43,14 +43,13 @@ public WindowsFolderWatcher(WindowsFolder folder)
43
43
{
44
44
Folder = folder ;
45
45
46
- _wndProc = new ( WndProc ) ;
47
- var pfnWndProc = ( delegate * unmanaged[ Stdcall] < HWND , uint , WPARAM , LPARAM , LRESULT > ) Marshal . GetFunctionPointerForDelegate ( _wndProc ) ;
48
-
49
46
fixed ( char * pszClassName = $ "FolderWatcherWindowClass{ Guid . NewGuid ( ) : B} ")
50
47
{
48
+ _wndProc = new ( WndProc ) ;
49
+
51
50
WNDCLASSEXW wndClass = default ;
52
51
wndClass . cbSize = ( uint ) sizeof ( WNDCLASSEXW ) ;
53
- wndClass . lpfnWndProc = pfnWndProc ;
52
+ wndClass . lpfnWndProc = ( delegate * unmanaged [ Stdcall ] < HWND , uint , WPARAM , LPARAM , LRESULT > ) Marshal . GetFunctionPointerForDelegate ( _wndProc ) ;
54
53
wndClass . hInstance = PInvoke . GetModuleHandle ( default ( PWSTR ) ) ;
55
54
wndClass . lpszClassName = pszClassName ;
56
55
@@ -70,20 +69,20 @@ private unsafe LRESULT WndProc(HWND hWnd, uint uMessage, WPARAM wParam, LPARAM l
70
69
ITEMIDLIST * pidl = default ;
71
70
IWindowsFolder folder = ( IWindowsFolder ) Folder ;
72
71
PInvoke . SHGetIDListFromObject ( ( IUnknown * ) folder . ThisPtr . Get ( ) , & pidl ) ;
73
- _pidl = pidl ;
72
+ _targetItemPIDL = pidl ;
74
73
75
74
SHChangeNotifyEntry changeNotifyEntry = default ;
76
75
changeNotifyEntry . pidl = pidl ;
77
76
78
- _registrationID = PInvoke . SHChangeNotifyRegister (
77
+ _watcherRegID = PInvoke . SHChangeNotifyRegister (
79
78
hWnd ,
80
79
SHCNRF_SOURCE . SHCNRF_ShellLevel | SHCNRF_SOURCE . SHCNRF_NewDelivery ,
81
80
( int ) SHCNE_ID . SHCNE_ALLEVENTS ,
82
81
WM_FOLDERWATCHER ,
83
82
1 ,
84
83
& changeNotifyEntry ) ;
85
84
86
- if ( _registrationID is 0U )
85
+ if ( _watcherRegID is 0U )
87
86
break ;
88
87
}
89
88
break ;
@@ -113,8 +112,8 @@ private unsafe LRESULT WndProc(HWND hWnd, uint uMessage, WPARAM wParam, LPARAM l
113
112
114
113
public void Dispose ( )
115
114
{
116
- PInvoke . SHChangeNotifyDeregister ( _registrationID ) ;
117
- PInvoke . CoTaskMemFree ( _pidl ) ;
115
+ PInvoke . SHChangeNotifyDeregister ( _watcherRegID ) ;
116
+ PInvoke . CoTaskMemFree ( _targetItemPIDL ) ;
118
117
PInvoke . CoUninitialize ( ) ;
119
118
PInvoke . PostQuitMessage ( 0 ) ;
120
119
}
0 commit comments