Selaa lähdekoodia

FIX: Windows 2000 compatibility

Alexander Koblov 4 vuotta sitten
vanhempi
commit
22d49acd94
2 muutettua tiedostoa jossa 24 lisäystä ja 5 poistoa
  1. 16 4
      src/platform/udrivewatcher.pas
  2. 8 1
      src/rpc/sys/win/uprocessinfo.pas

+ 16 - 4
src/platform/udrivewatcher.pas

@@ -165,6 +165,10 @@ end;
 const
   WM_USER_MEDIACHANGED = WM_USER + 200;
 
+var
+  SHChangeNotifyRegister: function(hwnd: HWND; fSources: Longint; fEvents: LONG; wMsg: UINT;
+                                   cEntries: Longint; pshcne: PSHChangeNotifyEntry): ULONG; stdcall;
+
 function MyWndProc(hWnd: HWND; uiMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
 var
   ADrive: TDrive;
@@ -257,11 +261,14 @@ begin
   {$PUSH}{$HINTS OFF}
   OldWProc := WNDPROC(SetWindowLongPtr(Handle, GWL_WNDPROC, LONG_PTR(@MyWndProc)));
   {$POP}
-  if Succeeded(SHGetFolderLocation(Handle, CSIDL_DRIVES, 0, 0, AEntries.pidl)) then
+  if Assigned(SHChangeNotifyRegister) then
   begin
-    AEntries.fRecursive:= False;
-    SHChangeNotifyRegister(Handle, SHCNRF_InterruptLevel or SHCNRF_ShellLevel or SHCNRF_RecursiveInterrupt,
-                           SHCNE_MEDIAINSERTED or SHCNE_MEDIAREMOVED, WM_USER_MEDIACHANGED, 1, @AEntries);
+    if Succeeded(SHGetFolderLocation(Handle, CSIDL_DRIVES, 0, 0, AEntries.pidl)) then
+    begin
+      AEntries.fRecursive:= False;
+      SHChangeNotifyRegister(Handle, SHCNRF_InterruptLevel or SHCNRF_ShellLevel or SHCNRF_RecursiveInterrupt,
+                             SHCNE_MEDIAINSERTED or SHCNE_MEDIAREMOVED, WM_USER_MEDIACHANGED, 1, @AEntries);
+    end;
   end;
 end;
 {$ENDIF}
@@ -1436,5 +1443,10 @@ begin
 end;
 {$ENDIF}
 
+{$IF DEFINED(MSWINDOWS)}
+initialization
+  Pointer(SHChangeNotifyRegister):= GetProcAddress(GetModuleHandle('shell32.dll'),
+                                                   'SHChangeNotifyRegister');
+{$ENDIF}
 end.
 

+ 8 - 1
src/rpc/sys/win/uprocessinfo.pas

@@ -14,7 +14,11 @@ function GetProcessFileNameEx(ProcessId: DWORD): UnicodeString;
 implementation
 
 uses
-  JwaTlHelp32, JwaPsApi;
+  JwaTlHelp32;
+
+var
+  GetProcessImageFileNameW: function(hProcess: HANDLE; lpImageFileName: LPWSTR;
+                                     nSize: DWORD): DWORD; stdcall;
 
 function GetParentProcessId(ProcessId: DWORD): DWORD;
 var
@@ -62,4 +66,7 @@ begin
   end;
 end;
 
+initialization
+  Pointer(GetProcessImageFileNameW):= GetProcAddress(GetModuleHandle('psapi.dll'),
+                                                     'GetProcessImageFileNameW');
 end.