Fix code assuming that the Reg* functions set the last error code
[reactos.git] / reactos / lib / userenv / desktop.c
index bf73535..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;
     }
 
@@ -363,7 +375,7 @@ AddDesktopItemW (BOOL bCommonDesktop,
   psl->lpVtbl->Release(psl);
 
   Ole32.fn.CoUninitialize();
-  
+
   UnloadDynamicImports(&Ole32);
 
   DPRINT ("AddDesktopItemW() done\n");