Fix code assuming that the Reg* functions set the last error code
[reactos.git] / reactos / lib / userenv / desktop.c
index 1d9260a..895aa3b 100644 (file)
  * PROGRAMMER:      Eric Kohl
  */
 
-#include "precomp.h"
-#include <shlobj.h>
+#include <precomp.h>
+
+#define NDEBUG
+#include <debug.h>
 
 
 /* FUNCTIONS ***************************************************************/
@@ -39,29 +41,34 @@ GetDesktopPath (BOOL bCommonPath,
   DWORD dwLength;
   DWORD dwType;
   HKEY hKey;
+  LONG Error;
 
   DPRINT ("GetDesktopPath() called\n");
 
-  if (RegOpenKeyExW (HKEY_CURRENT_USER,
-                    L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
-                    0,
-                    KEY_ALL_ACCESS,
-                    &hKey))
+  Error = RegOpenKeyExW (HKEY_CURRENT_USER,
+                        L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
+                        0,
+                        KEY_ALL_ACCESS,
+                        &hKey);
+  if (Error != ERROR_SUCCESS)
     {
       DPRINT1 ("RegOpenKeyExW() failed\n");
+      SetLastError((DWORD)Error);
       return FALSE;
     }
 
   dwLength = MAX_PATH * sizeof(WCHAR);
-  if (RegQueryValueExW (hKey,
-                       bCommonPath ? L"Common Desktop" : L"Desktop",
-                       0,
-                       &dwType,
-                       (LPBYTE)szPath,
-                       &dwLength))
+  Error = RegQueryValueExW (hKey,
+                           bCommonPath ? L"Common Desktop" : L"Desktop",
+                           0,
+                           &dwType,
+                           (LPBYTE)szPath,
+                          &dwLength);
+  if (Error != ERROR_SUCCESS)
     {
       DPRINT1 ("RegQueryValueExW() failed\n");
       RegCloseKey (hKey);
+      SetLastError((DWORD)Error);
       return FALSE;
     }
 
@@ -92,29 +99,34 @@ GetProgramsPath (BOOL bCommonPath,
   DWORD dwLength;
   DWORD dwType;
   HKEY hKey;
+  LONG Error;
 
   DPRINT ("GetProgramsPath() called\n");
 
-  if (RegOpenKeyExW (HKEY_CURRENT_USER,
-                    L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
-                    0,
-                    KEY_ALL_ACCESS,
-                    &hKey))
+  Error = RegOpenKeyExW (HKEY_CURRENT_USER,
+                        L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
+                        0,
+                        KEY_ALL_ACCESS,
+                        &hKey);
+  if (Error != ERROR_SUCCESS)
     {
       DPRINT1 ("RegOpenKeyExW() failed\n");
+      SetLastError((DWORD)Error);
       return FALSE;
     }
 
   dwLength = MAX_PATH * sizeof(WCHAR);
-  if (RegQueryValueExW (hKey,
-                       bCommonPath ? L"Common Programs" : L"Programs",
-                       0,
-                       &dwType,
-                       (LPBYTE)szPath,
-                       &dwLength))
+  Error = RegQueryValueExW (hKey,
+                           bCommonPath ? L"Common Programs" : L"Programs",
+                           0,
+                           &dwType,
+                           (LPBYTE)szPath,
+                           &dwLength);
+  if (Error != ERROR_SUCCESS)
     {
       DPRINT1 ("RegQueryValueExW() failed\n");
       RegCloseKey (hKey);
+      SetLastError((DWORD)Error);
       return FALSE;
     }
 
@@ -232,7 +244,7 @@ AddDesktopItemW (BOOL bCommonDesktop,
   WCHAR szLinkPath[MAX_PATH];
   WCHAR szArguments[MAX_PATH];
   WCHAR szCommand[MAX_PATH];
-  WIN32_FIND_DATA FindData;
+  WIN32_FIND_DATAW FindData;
   HANDLE hFind;
   LPWSTR Ptr;
   DWORD dwLength;
@@ -363,7 +375,7 @@ AddDesktopItemW (BOOL bCommonDesktop,
   psl->lpVtbl->Release(psl);
 
   Ole32.fn.CoUninitialize();
-  
+
   UnloadDynamicImports(&Ole32);
 
   DPRINT ("AddDesktopItemW() done\n");
@@ -416,7 +428,7 @@ DeleteDesktopItemW (BOOL bCommonItem,
   wcscat (szLinkPath, L".lnk");
   DPRINT ("Link path: '%S'\n", szLinkPath);
 
-  return DeleteFile (szLinkPath);
+  return DeleteFileW (szLinkPath);
 }
 
 
@@ -657,7 +669,7 @@ AddItemW (LPCWSTR lpGroupName,  /* Optional */
   WCHAR szLinkPath[MAX_PATH];
   WCHAR szArguments[MAX_PATH];
   WCHAR szCommand[MAX_PATH];
-  WIN32_FIND_DATA FindData;
+  WIN32_FIND_DATAW FindData;
   HANDLE hFind;
   LPWSTR Ptr;
   DWORD dwLength;