[LOCALSPL]
[reactos.git] / reactos / win32ss / printing / providers / localspl / printprocessors.c
index 5d6c178..2146742 100644 (file)
@@ -140,13 +140,21 @@ InitializePrintProcessorList()
         goto Cleanup;
     }
 
+    // LocalGetPrintProcessorDirectory returns the number of copied bytes. Convert this into a number of characters without the terminating null-character.
     cchPrintProcessorPath /= sizeof(WCHAR);
-    wszPrintProcessorPath[cchPrintProcessorPath++] = L'\\';
+    --cchPrintProcessorPath;
+
+    // Append a trailing backslash.
+    wszPrintProcessorPath[cchPrintProcessorPath] = L'\\';
+    ++cchPrintProcessorPath;
 
     // Open the environment registry key.
     dwErrorCode = _OpenEnvironment(NULL, &hKey);
     if (dwErrorCode != ERROR_SUCCESS)
+    {
+        ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode);
         goto Cleanup;
+    }
 
     // Open the "Print Processors" subkey.
     dwErrorCode = (DWORD)RegOpenKeyExW(hKey, L"Print Processors", 0, KEY_READ, &hSubKey);
@@ -477,7 +485,10 @@ LocalEnumPrintProcessors(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE
     // We use the registry and not the PrintProcessorList here, because the caller may request information about a different environment.
     dwErrorCode = _OpenEnvironment(pEnvironment, &hKey);
     if (dwErrorCode != ERROR_SUCCESS)
+    {
+        ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode);
         goto Cleanup;
+    }
 
     // Open the "Print Processors" subkey.
     dwErrorCode = (DWORD)RegOpenKeyExW(hKey, L"Print Processors", 0, KEY_READ, &hSubKey);
@@ -606,14 +617,15 @@ Cleanup:
  * A more specific error code can be obtained through GetLastError.
  */
 BOOL WINAPI
-LocalGetPrintProcessorDirectory(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded)
+LocalGetPrintProcessorDirectory(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded)
 {
     const WCHAR wszPath[] = L"\\PRTPROCS\\";
     const DWORD cchPath = _countof(wszPath) - 1;
 
-    DWORD cbDataWritten;
+    DWORD cbDirectoryName;
     DWORD dwErrorCode;
     HKEY hKey = NULL;
+    PWSTR pwszDirectory = (PWSTR)pPrintProcessorInfo;
 
     // Sanity checks
     if (Level != 1)
@@ -632,18 +644,20 @@ LocalGetPrintProcessorDirectory(LPWSTR pName, LPWSTR pEnvironment, DWORD Level,
     // Verify pEnvironment and open its registry key.
     dwErrorCode = _OpenEnvironment(pEnvironment, &hKey);
     if (dwErrorCode != ERROR_SUCCESS)
+    {
+        ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode);
         goto Cleanup;
+    }
 
     // Determine the size of the required buffer.
-    dwErrorCode = (DWORD)RegQueryValueExW(hKey, L"Directory", NULL, NULL, NULL, pcbNeeded);
+    dwErrorCode = (DWORD)RegQueryValueExW(hKey, L"Directory", NULL, NULL, NULL, &cbDirectoryName);
     if (dwErrorCode != ERROR_SUCCESS)
     {
         ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode);
         goto Cleanup;
     }
 
-    *pcbNeeded += cchSpoolDirectory;
-    *pcbNeeded += cchPath;
+    *pcbNeeded = (cchSpoolDirectory + cchPath) * sizeof(WCHAR) + cbDirectoryName;
 
     // Is the supplied buffer large enough?
     if (cbBuf < *pcbNeeded)
@@ -653,11 +667,11 @@ LocalGetPrintProcessorDirectory(LPWSTR pName, LPWSTR pEnvironment, DWORD Level,
     }
 
     // Copy the path to the "prtprocs" directory into pPrintProcessorInfo
-    CopyMemory(pPrintProcessorInfo, wszSpoolDirectory, cchSpoolDirectory * sizeof(WCHAR));
-    CopyMemory(&pPrintProcessorInfo[cchSpoolDirectory], wszPath, cchPath * sizeof(WCHAR));
+    CopyMemory(pwszDirectory, wszSpoolDirectory, cchSpoolDirectory * sizeof(WCHAR));
+    CopyMemory(&pwszDirectory[cchSpoolDirectory], wszPath, cchPath * sizeof(WCHAR));
 
     // Get the directory name from the registry.
-    dwErrorCode = (DWORD)RegQueryValueExW(hKey, L"Directory", NULL, NULL, &pPrintProcessorInfo[cchSpoolDirectory + cchPath], &cbDataWritten);
+    dwErrorCode = (DWORD)RegQueryValueExW(hKey, L"Directory", NULL, NULL, (PBYTE)&pwszDirectory[cchSpoolDirectory + cchPath], &cbDirectoryName);
     if (dwErrorCode != ERROR_SUCCESS)
     {
         ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode);