[WINSPOOL] GetPrinterDriverA(): Refactor failure handling (#2832)
[reactos.git] / win32ss / printing / base / winspool / printers.c
index 219e831..249d412 100644 (file)
@@ -472,7 +472,6 @@ BOOL WINAPI
 EnumPrintersA(DWORD Flags, PSTR Name, DWORD Level, PBYTE pPrinterEnum, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
 {
     DWORD dwErrorCode;
-    BOOL bResult;
     DWORD cch;
     PWSTR pwszName = NULL;
     PSTR pszPrinterName = NULL;
@@ -525,8 +524,7 @@ EnumPrintersA(DWORD Flags, PSTR Name, DWORD Level, PBYTE pPrinterEnum, DWORD cbB
     }
  
     /* Ref: https://stackoverflow.com/questions/41147180/why-enumprintersa-and-enumprintersw-request-the-same-amount-of-memory */
-    bResult = EnumPrintersW(Flags, pwszName, Level, pPrinterEnum, cbBuf, pcbNeeded, pcReturned);
-    if (!bResult)
+    if (!EnumPrintersW(Flags, pwszName, Level, pPrinterEnum, cbBuf, pcbNeeded, pcReturned))
     {
         dwErrorCode = GetLastError();
         goto Cleanup;
@@ -1117,6 +1115,7 @@ Cleanup:
 BOOL WINAPI
 GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD pcbNeeded)
 {
+    DWORD dwErrorCode;
     PPRINTER_INFO_1A ppi1a = (PPRINTER_INFO_1A)pPrinter;
     PPRINTER_INFO_1W ppi1w = (PPRINTER_INFO_1W)pPrinter;
     PPRINTER_INFO_2A ppi2a = (PPRINTER_INFO_2A)pPrinter;
@@ -1128,23 +1127,20 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
     PPRINTER_INFO_7A ppi7a = (PPRINTER_INFO_7A)pPrinter;
     PPRINTER_INFO_7W ppi7w = (PPRINTER_INFO_7W)pPrinter;
     DWORD cch;
-    BOOL bReturnValue = FALSE;
 
     TRACE("GetPrinterA(%p, %lu, %p, %lu, %p)\n", hPrinter, Level, pPrinter, cbBuf, pcbNeeded);
 
     // Check for invalid levels here for early error return. Should be 1-9.
     if (Level <  1 || Level > 9)
     {
-        SetLastError(ERROR_INVALID_LEVEL);
+        dwErrorCode = ERROR_INVALID_LEVEL;
         ERR("Invalid Level!\n");
         goto Cleanup;
     }
 
-    bReturnValue = GetPrinterW(hPrinter, Level, pPrinter, cbBuf, pcbNeeded);
-
-    if (!bReturnValue)
+    if (!GetPrinterW(hPrinter, Level, pPrinter, cbBuf, pcbNeeded))
     {
-        TRACE("GetPrinterW failed!\n");
+        dwErrorCode = GetLastError();
         goto Cleanup;
     }
 
@@ -1162,7 +1158,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszDescription = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszDescription)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1183,7 +1179,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszName)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1204,7 +1200,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszComment = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszComment)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1229,7 +1225,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszServerName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszServerName)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1250,7 +1246,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszPrinterName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszPrinterName)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1271,7 +1267,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszShareName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszShareName)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1292,7 +1288,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszPortName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszPortName)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1313,7 +1309,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszDriverName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszDriverName)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1334,7 +1330,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszComment = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszComment)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1355,7 +1351,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszLocation = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszLocation)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1376,7 +1372,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszSepFile = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszSepFile)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1397,7 +1393,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszPrintProcessor = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszPrintProcessor)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1418,7 +1414,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszDatatype = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszDatatype)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1439,7 +1435,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszParameters = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszParameters)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1464,7 +1460,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszPrinterName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszPrinterName)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1485,7 +1481,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszServerName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszServerName)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1510,7 +1506,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszPrinterName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszPrinterName)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1531,7 +1527,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszPortName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszPortName)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1556,7 +1552,7 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
                 pszaObjectGUID = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
                 if (!pszaObjectGUID)
                 {
-                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+                    dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
                     ERR("HeapAlloc failed!\n");
                     goto Cleanup;
                 }
@@ -1570,13 +1566,17 @@ GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD
         }
     }       // switch
 
+    dwErrorCode = ERROR_SUCCESS;
+
 Cleanup:
-    return bReturnValue;
+    SetLastError(dwErrorCode);
+    return (dwErrorCode == ERROR_SUCCESS);
 }
 
 BOOL WINAPI
 GetPrinterDriverA(HANDLE hPrinter, LPSTR pEnvironment, DWORD Level, LPBYTE pDriverInfo, DWORD cbBuf, LPDWORD pcbNeeded)
 {   
+    DWORD dwErrorCode;
     /*
      * We are mapping multiple different pointers to the same pDriverInfo pointer here so that
      * we can use the same incoming pointer for different Levels
@@ -1588,7 +1588,6 @@ GetPrinterDriverA(HANDLE hPrinter, LPSTR pEnvironment, DWORD Level, LPBYTE pDriv
     PDRIVER_INFO_5W pdi5w = (PDRIVER_INFO_5W)pDriverInfo;
     PDRIVER_INFO_6W pdi6w = (PDRIVER_INFO_6W)pDriverInfo;
 
-    BOOL bReturnValue = FALSE;
     DWORD cch;
     PWSTR pwszEnvironment = NULL;
 
@@ -1597,9 +1596,9 @@ GetPrinterDriverA(HANDLE hPrinter, LPSTR pEnvironment, DWORD Level, LPBYTE pDriv
     // Check for invalid levels here for early error return. Should be 1-6.
     if (Level <  1 || Level > 6)
     {
-        SetLastError(ERROR_INVALID_LEVEL);
+        dwErrorCode = ERROR_INVALID_LEVEL;
         ERR("Invalid Level!\n");
-        goto Exit;
+        goto Cleanup;
     }
 
     if (pEnvironment)
@@ -1610,26 +1609,18 @@ GetPrinterDriverA(HANDLE hPrinter, LPSTR pEnvironment, DWORD Level, LPBYTE pDriv
         pwszEnvironment = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
         if (!pwszEnvironment)
         {
-            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+            dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
             ERR("HeapAlloc failed!\n");
-            goto Exit;
+            goto Cleanup;
         }
 
         MultiByteToWideChar(CP_ACP, 0, pEnvironment, -1, pwszEnvironment, cch + 1);
     }
 
-    bReturnValue = GetPrinterDriverW(hPrinter, pwszEnvironment, Level, pDriverInfo, cbBuf, pcbNeeded);
-    TRACE("*pcbNeeded is '%d' and bReturnValue is '%d' and GetLastError is '%ld'.\n", *pcbNeeded, bReturnValue, GetLastError());
-
-    if (pwszEnvironment)
-    {
-        HeapFree(hProcessHeap, 0, pwszEnvironment);
-    }
-
-    if (!bReturnValue)
+    if (!GetPrinterDriverW(hPrinter, pwszEnvironment, Level, pDriverInfo, cbBuf, pcbNeeded))
     {
-        TRACE("GetPrinterDriverW failed!\n");
-        goto Exit;
+        dwErrorCode = GetLastError();
+        goto Cleanup;
     }
 
     // Do Unicode to ANSI conversions for strings based on Level
@@ -1637,170 +1628,307 @@ GetPrinterDriverA(HANDLE hPrinter, LPSTR pEnvironment, DWORD Level, LPBYTE pDriv
     {
         case 1:
         {
-            if (!UnicodeToAnsiInPlace(pdi1w->pName))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi1w->pName);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
             break;
         }
 
         case 2:
         {
-            if (!UnicodeToAnsiInPlace(pdi2w->pName))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi2w->pName);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi2w->pEnvironment))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi2w->pEnvironment);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi2w->pDriverPath))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi2w->pDriverPath);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi2w->pDataFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi2w->pDataFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi2w->pConfigFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi2w->pConfigFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
             break;
         }
 
         case 3:
         {
-            if (!UnicodeToAnsiInPlace(pdi3w->pName))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi3w->pName);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi3w->pEnvironment))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi3w->pEnvironment);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi3w->pDriverPath))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi3w->pDriverPath);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi3w->pDataFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi3w->pDataFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi3w->pConfigFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi3w->pConfigFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi3w->pHelpFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi3w->pHelpFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi3w->pDependentFiles))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi3w->pDependentFiles);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi3w->pMonitorName))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi3w->pMonitorName);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
  
-            if (!UnicodeToAnsiInPlace(pdi3w->pDefaultDataType))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi3w->pDefaultDataType);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
             break;
         }
 
         case 4:
         {
-            if (!UnicodeToAnsiInPlace(pdi4w->pName))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi4w->pName);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi4w->pEnvironment))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi4w->pEnvironment);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi4w->pDriverPath))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi4w->pDriverPath);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi4w->pDataFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi4w->pDataFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi4w->pConfigFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi4w->pConfigFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi4w->pHelpFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi4w->pHelpFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi4w->pDependentFiles))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi4w->pDependentFiles);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi4w->pMonitorName))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi4w->pMonitorName);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
  
-            if (!UnicodeToAnsiInPlace(pdi4w->pDefaultDataType))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi4w->pDefaultDataType);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi4w->pszzPreviousNames))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi4w->pszzPreviousNames);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
             break;
         }
 
         case 5:
         {
-            if (!UnicodeToAnsiInPlace(pdi5w->pName))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi5w->pName);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi5w->pEnvironment))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi5w->pEnvironment);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi5w->pDriverPath))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi5w->pDriverPath);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi5w->pDataFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi5w->pDataFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi5w->pConfigFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi5w->pConfigFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
             break;
         }
 
         case 6:
         {
-            if (!UnicodeToAnsiInPlace(pdi6w->pName))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pName);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi6w->pEnvironment))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pEnvironment);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi6w->pDriverPath))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pDriverPath);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi6w->pDataFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pDataFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi6w->pConfigFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pConfigFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi6w->pHelpFile))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pHelpFile);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi6w->pDependentFiles))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pDependentFiles);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi6w->pMonitorName))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pMonitorName);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
  
-            if (!UnicodeToAnsiInPlace(pdi6w->pDefaultDataType))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pDefaultDataType);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi6w->pszzPreviousNames))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pszzPreviousNames);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi6w->pszMfgName))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pszMfgName);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi6w->pszOEMUrl))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pszOEMUrl);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi6w->pszHardwareID))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pszHardwareID);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
 
-            if (!UnicodeToAnsiInPlace(pdi6w->pszProvider))
-                goto Exit;
+            dwErrorCode = UnicodeToAnsiInPlace(pdi6w->pszProvider);
+            if (dwErrorCode != ERROR_SUCCESS)
+            {
+                goto Cleanup;
+            }
         }
     }
 
-    bReturnValue = TRUE;
+    dwErrorCode = ERROR_SUCCESS;
 
-Exit:
+Cleanup:
+    if (pwszEnvironment)
+    {
+        HeapFree(hProcessHeap, 0, pwszEnvironment);
+    }
 
-    return bReturnValue;
+    SetLastError(dwErrorCode);
+    return (dwErrorCode == ERROR_SUCCESS);
 }
 
 BOOL WINAPI