2 * PROJECT: ReactOS Local Spooler
3 * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation
4 * PURPOSE: Functions related to Print Processors
5 * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
12 static LIST_ENTRY _PrintProcessorList
;
15 * @name _OpenEnvironment
17 * Checks a supplied pEnvironment variable for validity and opens its registry key.
20 * The pEnvironment variable to check. Can be NULL to use the current environment.
23 * On success, this variable will contain a HKEY to the opened registry key of the environment.
24 * You can use it for further tasks and have to close it with RegCloseKey.
27 * A Windows Error Code indicating success or failure.
30 _OpenEnvironment(PCWSTR pEnvironment
, PHKEY hKey
)
32 const WCHAR wszEnvironmentsKey
[] = L
"SYSTEM\\CurrentControlSet\\Control\\Print\\Environments\\";
33 const DWORD cchEnvironmentsKey
= _countof(wszEnvironmentsKey
) - 1;
37 PWSTR pwszEnvironmentKey
= NULL
;
39 // Use the current environment if none was supplied.
41 pEnvironment
= wszCurrentEnvironment
;
43 // Construct the registry key of the demanded environment.
44 cchEnvironment
= wcslen(pEnvironment
);
45 pwszEnvironmentKey
= DllAllocSplMem((cchEnvironmentsKey
+ cchEnvironment
+ 1) * sizeof(WCHAR
));
46 if (!pwszEnvironmentKey
)
48 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
52 CopyMemory(pwszEnvironmentKey
, wszEnvironmentsKey
, cchEnvironmentsKey
* sizeof(WCHAR
));
53 CopyMemory(&pwszEnvironmentKey
[cchEnvironmentsKey
], pEnvironment
, (cchEnvironment
+ 1) * sizeof(WCHAR
));
55 // Open the registry key.
56 dwErrorCode
= (DWORD
)RegOpenKeyExW(HKEY_LOCAL_MACHINE
, pwszEnvironmentKey
, 0, KEY_READ
, hKey
);
57 if (dwErrorCode
== ERROR_FILE_NOT_FOUND
)
59 dwErrorCode
= ERROR_INVALID_ENVIRONMENT
;
62 else if (dwErrorCode
!= ERROR_SUCCESS
)
64 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
69 if (pwszEnvironmentKey
)
70 DllFreeSplMem(pwszEnvironmentKey
);
76 FindDatatype(const PLOCAL_PRINT_PROCESSOR pPrintProcessor
, PCWSTR pwszDatatype
)
79 PDATATYPES_INFO_1W pCurrentDatatype
= pPrintProcessor
->pDatatypesInfo1
;
81 for (i
= 0; i
< pPrintProcessor
->dwDatatypeCount
; i
++)
83 if (wcsicmp(pCurrentDatatype
->pName
, pwszDatatype
) == 0)
92 PLOCAL_PRINT_PROCESSOR
93 FindPrintProcessor(PCWSTR pwszName
)
96 PLOCAL_PRINT_PROCESSOR pPrintProcessor
;
98 for (pEntry
= _PrintProcessorList
.Flink
; pEntry
!= &_PrintProcessorList
; pEntry
= pEntry
->Flink
)
100 pPrintProcessor
= CONTAINING_RECORD(pEntry
, LOCAL_PRINT_PROCESSOR
, Entry
);
102 if (wcsicmp(pPrintProcessor
->pwszName
, pwszName
) == 0)
103 return pPrintProcessor
;
110 * @name InitializePrintProcessorList
112 * Initializes a singly linked list of locally available Print Processors.
115 InitializePrintProcessorList()
119 DWORD cchPrintProcessorPath
;
121 DWORD cchPrintProcessorName
;
125 HINSTANCE hinstPrintProcessor
;
128 HKEY hSubSubKey
= NULL
;
129 PLOCAL_PRINT_PROCESSOR pPrintProcessor
= NULL
;
130 WCHAR wszFileName
[MAX_PATH
];
131 WCHAR wszPrintProcessorPath
[MAX_PATH
];
133 // Initialize an empty list for our Print Processors.
134 InitializeListHead(&_PrintProcessorList
);
136 // Prepare the path to the Print Processor directory.
137 if (!LocalGetPrintProcessorDirectory(NULL
, NULL
, 1, (PBYTE
)wszPrintProcessorPath
, sizeof(wszPrintProcessorPath
), &cchPrintProcessorPath
))
139 dwErrorCode
= GetLastError();
143 // LocalGetPrintProcessorDirectory returns the number of copied bytes. Convert this into a number of characters without the terminating null-character.
144 cchPrintProcessorPath
/= sizeof(WCHAR
);
145 --cchPrintProcessorPath
;
147 // Append a trailing backslash.
148 wszPrintProcessorPath
[cchPrintProcessorPath
] = L
'\\';
149 ++cchPrintProcessorPath
;
151 // Open the environment registry key.
152 dwErrorCode
= _OpenEnvironment(NULL
, &hKey
);
153 if (dwErrorCode
!= ERROR_SUCCESS
)
155 ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode
);
159 // Open the "Print Processors" subkey.
160 dwErrorCode
= (DWORD
)RegOpenKeyExW(hKey
, L
"Print Processors", 0, KEY_READ
, &hSubKey
);
161 if (dwErrorCode
!= ERROR_SUCCESS
)
163 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
167 // Get the number of Print Processors and maximum sub key length.
168 dwErrorCode
= (DWORD
)RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwSubKeys
, &cchMaxSubKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
169 if (dwErrorCode
!= ERROR_SUCCESS
)
171 ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode
);
175 // Loop through all available local Print Processors.
176 for (i
= 0; i
< dwSubKeys
; i
++)
178 // Cleanup tasks from the previous run
181 RegCloseKey(hSubSubKey
);
187 if (pPrintProcessor
->pwszName
)
188 DllFreeSplStr(pPrintProcessor
->pwszName
);
190 if (pPrintProcessor
->pDatatypesInfo1
)
191 DllFreeSplMem(pPrintProcessor
->pDatatypesInfo1
);
193 DllFreeSplMem(pPrintProcessor
);
194 pPrintProcessor
= NULL
;
197 // Create a new LOCAL_PRINT_PROCESSOR structure for it.
198 pPrintProcessor
= DllAllocSplMem(sizeof(LOCAL_PRINT_PROCESSOR
));
199 if (!pPrintProcessor
)
201 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
202 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
206 // Allocate memory for the Print Monitor Name.
207 pPrintProcessor
->pwszName
= DllAllocSplMem((cchMaxSubKey
+ 1) * sizeof(WCHAR
));
208 if (!pPrintProcessor
->pwszName
)
210 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
211 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
215 // Get the name of this Print Processor.
216 cchPrintProcessorName
= cchMaxSubKey
+ 1;
217 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, pPrintProcessor
->pwszName
, &cchPrintProcessorName
, NULL
, NULL
, NULL
, NULL
);
218 if (dwErrorCode
!= ERROR_SUCCESS
)
220 ERR("RegEnumKeyExW failed with status %ld!\n", dwErrorCode
);
224 // Open this Print Processor's registry key.
225 dwErrorCode
= (DWORD
)RegOpenKeyExW(hSubKey
, pPrintProcessor
->pwszName
, 0, KEY_READ
, &hSubSubKey
);
226 if (dwErrorCode
!= ERROR_SUCCESS
)
228 ERR("RegOpenKeyExW failed for Print Processor \"%S\" with status %lu!\n", pPrintProcessor
->pwszName
, dwErrorCode
);
232 // Get the file name of the Print Processor.
233 cbFileName
= sizeof(wszFileName
);
234 dwErrorCode
= (DWORD
)RegQueryValueExW(hSubSubKey
, L
"Driver", NULL
, NULL
, (PBYTE
)wszFileName
, &cbFileName
);
235 if (dwErrorCode
!= ERROR_SUCCESS
)
237 ERR("RegQueryValueExW failed for Print Processor \"%S\" with status %lu!\n", pPrintProcessor
->pwszName
, dwErrorCode
);
241 // Verify that our buffer is large enough.
242 if (cchPrintProcessorPath
+ cbFileName
/ sizeof(WCHAR
) > MAX_PATH
)
244 ERR("Print Processor directory \"%S\" for Print Processor \"%S\" is too long!\n", wszFileName
, pPrintProcessor
->pwszName
);
248 // Construct the full path to the Print Processor.
249 CopyMemory(&wszPrintProcessorPath
[cchPrintProcessorPath
], wszFileName
, cbFileName
);
252 hinstPrintProcessor
= LoadLibraryW(wszPrintProcessorPath
);
253 if (!hinstPrintProcessor
)
255 ERR("LoadLibraryW failed for \"%S\" with error %lu!\n", wszPrintProcessorPath
, GetLastError());
259 // Get and verify all its function pointers.
260 pPrintProcessor
->pfnClosePrintProcessor
= (PClosePrintProcessor
)GetProcAddress(hinstPrintProcessor
, "ClosePrintProcessor");
261 if (!pPrintProcessor
->pfnClosePrintProcessor
)
263 ERR("Print Processor \"%S\" exports no ClosePrintProcessor!\n", wszPrintProcessorPath
);
267 pPrintProcessor
->pfnControlPrintProcessor
= (PControlPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "ControlPrintProcessor");
268 if (!pPrintProcessor
->pfnControlPrintProcessor
)
270 ERR("Print Processor \"%S\" exports no ControlPrintProcessor!\n", wszPrintProcessorPath
);
274 pPrintProcessor
->pfnEnumPrintProcessorDatatypesW
= (PEnumPrintProcessorDatatypesW
)GetProcAddress(hinstPrintProcessor
, "EnumPrintProcessorDatatypesW");
275 if (!pPrintProcessor
->pfnEnumPrintProcessorDatatypesW
)
277 ERR("Print Processor \"%S\" exports no EnumPrintProcessorDatatypesW!\n", wszPrintProcessorPath
);
281 pPrintProcessor
->pfnGetPrintProcessorCapabilities
= (PGetPrintProcessorCapabilities
)GetProcAddress(hinstPrintProcessor
, "GetPrintProcessorCapabilities");
282 if (!pPrintProcessor
->pfnGetPrintProcessorCapabilities
)
284 ERR("Print Processor \"%S\" exports no GetPrintProcessorCapabilities!\n", wszPrintProcessorPath
);
288 pPrintProcessor
->pfnOpenPrintProcessor
= (POpenPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "OpenPrintProcessor");
289 if (!pPrintProcessor
->pfnOpenPrintProcessor
)
291 ERR("Print Processor \"%S\" exports no OpenPrintProcessor!\n", wszPrintProcessorPath
);
295 pPrintProcessor
->pfnPrintDocumentOnPrintProcessor
= (PPrintDocumentOnPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "PrintDocumentOnPrintProcessor");
296 if (!pPrintProcessor
->pfnPrintDocumentOnPrintProcessor
)
298 ERR("Print Processor \"%S\" exports no PrintDocumentOnPrintProcessor!\n", wszPrintProcessorPath
);
302 // Get all supported datatypes.
303 pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(NULL
, NULL
, 1, NULL
, 0, &cbDatatypes
, &pPrintProcessor
->dwDatatypeCount
);
304 pPrintProcessor
->pDatatypesInfo1
= DllAllocSplMem(cbDatatypes
);
305 if (!pPrintProcessor
->pDatatypesInfo1
)
307 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
308 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
312 if (!pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(NULL
, NULL
, 1, (PBYTE
)pPrintProcessor
->pDatatypesInfo1
, cbDatatypes
, &cbDatatypes
, &pPrintProcessor
->dwDatatypeCount
))
314 ERR("EnumPrintProcessorDatatypesW failed for Print Processor \"%S\" with error %lu!\n", wszPrintProcessorPath
, GetLastError());
318 // Add the Print Processor to the list.
319 InsertTailList(&_PrintProcessorList
, &pPrintProcessor
->Entry
);
321 // Don't let the cleanup routines free this.
322 pPrintProcessor
= NULL
;
325 dwErrorCode
= ERROR_SUCCESS
;
330 RegCloseKey(hSubSubKey
);
334 if (pPrintProcessor
->pwszName
)
335 DllFreeSplStr(pPrintProcessor
->pwszName
);
337 if (pPrintProcessor
->pDatatypesInfo1
)
338 DllFreeSplMem(pPrintProcessor
->pDatatypesInfo1
);
340 DllFreeSplMem(pPrintProcessor
);
345 RegCloseKey(hSubKey
);
350 SetLastError(dwErrorCode
);
351 return (dwErrorCode
== ERROR_SUCCESS
);
355 * @name LocalEnumPrintProcessorDatatypes
357 * Obtains an array of all datatypes supported by a particular Print Processor.
358 * Print Provider function for EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW.
361 * Server Name. Ignored here, because every caller of LocalEnumPrintProcessorDatatypes is interested in the local directory.
363 * @param pPrintProcessorName
364 * The (case-insensitive) name of the Print Processor to query.
367 * The level of the structure supplied through pDatatypes. This must be 1.
370 * Pointer to the buffer that receives an array of DATATYPES_INFO_1W structures.
371 * Can be NULL if you just want to know the required size of the buffer.
374 * Size of the buffer you supplied for pDatatypes, in bytes.
377 * Pointer to a variable that receives the required size of the buffer for pDatatypes, in bytes.
378 * This parameter mustn't be NULL!
381 * Pointer to a variable that receives the number of elements of the DATATYPES_INFO_1W array.
382 * This parameter mustn't be NULL!
385 * TRUE if we successfully copied the array into pDatatypes, FALSE otherwise.
386 * A more specific error code can be obtained through GetLastError.
389 LocalEnumPrintProcessorDatatypes(LPWSTR pName
, LPWSTR pPrintProcessorName
, DWORD Level
, LPBYTE pDatatypes
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
)
392 PLOCAL_PRINT_PROCESSOR pPrintProcessor
;
397 dwErrorCode
= ERROR_INVALID_LEVEL
;
401 // Try to find the Print Processor.
402 pPrintProcessor
= FindPrintProcessor(pPrintProcessorName
);
403 if (!pPrintProcessor
)
405 dwErrorCode
= ERROR_UNKNOWN_PRINTPROCESSOR
;
409 // Call its EnumPrintProcessorDatatypesW function.
410 if (pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(pName
, pPrintProcessorName
, Level
, pDatatypes
, cbBuf
, pcbNeeded
, pcReturned
))
411 dwErrorCode
= ERROR_SUCCESS
;
413 dwErrorCode
= GetLastError();
416 SetLastError(dwErrorCode
);
417 return (dwErrorCode
== ERROR_SUCCESS
);
421 * @name LocalEnumPrintProcessors
423 * Obtains an array of all available Print Processors on this computer.
424 * Print Provider function for EnumPrintProcessorsA/EnumPrintProcessorsW.
427 * Server Name. Ignored here, because every caller of LocalEnumPrintProcessors is interested in the local directory.
429 * @param pEnvironment
430 * One of the predefined operating system and architecture "environment" strings (like "Windows NT x86").
431 * Alternatively, NULL to output the Print Processor directory of the current environment.
434 * The level of the structure supplied through pPrintProcessorInfo. This must be 1.
436 * @param pPrintProcessorInfo
437 * Pointer to the buffer that receives an array of PRINTPROCESSOR_INFO_1W structures.
438 * Can be NULL if you just want to know the required size of the buffer.
441 * Size of the buffer you supplied for pPrintProcessorInfo, in bytes.
444 * Pointer to a variable that receives the required size of the buffer for pPrintProcessorInfo, in bytes.
445 * This parameter mustn't be NULL!
448 * Pointer to a variable that receives the number of elements of the PRINTPROCESSOR_INFO_1W array.
449 * This parameter mustn't be NULL!
452 * TRUE if we successfully copied the array into pPrintProcessorInfo, FALSE otherwise.
453 * A more specific error code can be obtained through GetLastError.
456 LocalEnumPrintProcessors(LPWSTR pName
, LPWSTR pEnvironment
, DWORD Level
, LPBYTE pPrintProcessorInfo
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
)
459 DWORD cchPrintProcessor
;
461 DWORD dwPrintProcessorCount
;
465 PBYTE pCurrentOutputPrintProcessor
;
466 PBYTE pCurrentOutputPrintProcessorInfo
;
467 PRINTPROCESSOR_INFO_1W PrintProcessorInfo1
;
468 PWSTR pwszTemp
= NULL
;
473 dwErrorCode
= ERROR_INVALID_LEVEL
;
477 if (!pcbNeeded
|| !pcReturned
)
479 // This error is also caught by RPC and returned as RPC_X_NULL_REF_POINTER.
480 dwErrorCode
= ERROR_INVALID_PARAMETER
;
484 // Verify pEnvironment and open its registry key.
485 // We use the registry and not the PrintProcessorList here, because the caller may request information about a different environment.
486 dwErrorCode
= _OpenEnvironment(pEnvironment
, &hKey
);
487 if (dwErrorCode
!= ERROR_SUCCESS
)
489 ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode
);
493 // Open the "Print Processors" subkey.
494 dwErrorCode
= (DWORD
)RegOpenKeyExW(hKey
, L
"Print Processors", 0, KEY_READ
, &hSubKey
);
495 if (dwErrorCode
!= ERROR_SUCCESS
)
497 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
501 // Get the number of Print Processors and maximum sub key length.
502 dwErrorCode
= (DWORD
)RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwPrintProcessorCount
, &cchMaxSubKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
503 if (dwErrorCode
!= ERROR_SUCCESS
)
505 ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode
);
509 // Allocate a temporary buffer to let RegEnumKeyExW succeed.
510 pwszTemp
= DllAllocSplMem((cchMaxSubKey
+ 1) * sizeof(WCHAR
));
513 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
514 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
518 // Determine the required size of the output buffer.
521 for (i
= 0; i
< dwPrintProcessorCount
; i
++)
523 // RegEnumKeyExW sucks! Unlike similar API functions, it only returns the actual numbers of characters copied when you supply a buffer large enough.
524 // So use pwszTemp with its size cchMaxSubKey for this.
525 cchPrintProcessor
= cchMaxSubKey
+ 1;
526 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, pwszTemp
, &cchPrintProcessor
, NULL
, NULL
, NULL
, NULL
);
527 if (dwErrorCode
!= ERROR_SUCCESS
)
529 ERR("RegEnumKeyExW failed with status %lu!\n", dwErrorCode
);
533 *pcbNeeded
+= sizeof(PRINTPROCESSOR_INFO_1W
) + (cchPrintProcessor
+ 1) * sizeof(WCHAR
);
536 // Check if the supplied buffer is large enough.
537 if (cbBuf
< *pcbNeeded
)
539 dwErrorCode
= ERROR_INSUFFICIENT_BUFFER
;
543 // Put the Print Processor strings right after the last PRINTPROCESSOR_INFO_1W structure.
544 pCurrentOutputPrintProcessorInfo
= pPrintProcessorInfo
;
545 pCurrentOutputPrintProcessor
= pPrintProcessorInfo
+ dwPrintProcessorCount
* sizeof(PRINTPROCESSOR_INFO_1W
);
547 // Copy over all Print Processors.
548 for (i
= 0; i
< dwPrintProcessorCount
; i
++)
550 // This isn't really correct, but doesn't cause any harm, because we've extensively checked the size of the supplied buffer above.
551 cchPrintProcessor
= cchMaxSubKey
+ 1;
553 // Copy the Print Processor name.
554 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, (PWSTR
)pCurrentOutputPrintProcessor
, &cchPrintProcessor
, NULL
, NULL
, NULL
, NULL
);
555 if (dwErrorCode
!= ERROR_SUCCESS
)
557 ERR("RegEnumKeyExW failed with status %lu!\n", dwErrorCode
);
561 // Fill and copy the PRINTPROCESSOR_INFO_1W structure belonging to this Print Processor.
562 PrintProcessorInfo1
.pName
= (PWSTR
)pCurrentOutputPrintProcessor
;
563 CopyMemory(pCurrentOutputPrintProcessorInfo
, &PrintProcessorInfo1
, sizeof(PRINTPROCESSOR_INFO_1W
));
565 // Advance to the next PRINTPROCESSOR_INFO_1W location and string location in the output buffer.
566 pCurrentOutputPrintProcessor
+= (cchPrintProcessor
+ 1) * sizeof(WCHAR
);
567 pCurrentOutputPrintProcessorInfo
+= sizeof(PRINTPROCESSOR_INFO_1W
);
570 // We've finished successfully!
571 *pcReturned
= dwPrintProcessorCount
;
572 dwErrorCode
= ERROR_SUCCESS
;
576 DllFreeSplMem(pwszTemp
);
579 RegCloseKey(hSubKey
);
584 SetLastError(dwErrorCode
);
585 return (dwErrorCode
== ERROR_SUCCESS
);
589 * @name LocalGetPrintProcessorDirectory
591 * Obtains the path to the local Print Processor directory.
592 * Print Provider function for GetPrintProcessorDirectoryA/GetPrintProcessorDirectoryW.
595 * Server Name. Ignored here, because every caller of LocalGetPrintProcessorDirectory is interested in the local directory.
597 * @param pEnvironment
598 * One of the predefined operating system and architecture "environment" strings (like "Windows NT x86").
599 * Alternatively, NULL to output the Print Processor directory of the current environment.
602 * The level of the (non-existing) structure supplied through pPrintProcessorInfo. This must be 1.
604 * @param pPrintProcessorInfo
605 * Pointer to the buffer that receives the full path to the Print Processor directory.
606 * Can be NULL if you just want to know the required size of the buffer.
609 * Size of the buffer you supplied for pPrintProcessorInfo, in bytes.
612 * Pointer to a variable that receives the required size of the buffer for pPrintProcessorInfo, in bytes.
613 * This parameter mustn't be NULL!
616 * TRUE if we successfully copied the directory into pPrintProcessorInfo, FALSE otherwise.
617 * A more specific error code can be obtained through GetLastError.
620 LocalGetPrintProcessorDirectory(PWSTR pName
, PWSTR pEnvironment
, DWORD Level
, PBYTE pPrintProcessorInfo
, DWORD cbBuf
, PDWORD pcbNeeded
)
622 const WCHAR wszPath
[] = L
"\\PRTPROCS\\";
623 const DWORD cchPath
= _countof(wszPath
) - 1;
625 DWORD cbDirectoryName
;
628 PWSTR pwszDirectory
= (PWSTR
)pPrintProcessorInfo
;
633 dwErrorCode
= ERROR_INVALID_LEVEL
;
639 // This error is also caught by RPC and returned as RPC_X_NULL_REF_POINTER.
640 dwErrorCode
= ERROR_INVALID_PARAMETER
;
644 // Verify pEnvironment and open its registry key.
645 dwErrorCode
= _OpenEnvironment(pEnvironment
, &hKey
);
646 if (dwErrorCode
!= ERROR_SUCCESS
)
648 ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode
);
652 // Determine the size of the required buffer.
653 dwErrorCode
= (DWORD
)RegQueryValueExW(hKey
, L
"Directory", NULL
, NULL
, NULL
, &cbDirectoryName
);
654 if (dwErrorCode
!= ERROR_SUCCESS
)
656 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode
);
660 *pcbNeeded
= (cchSpoolDirectory
+ cchPath
) * sizeof(WCHAR
) + cbDirectoryName
;
662 // Is the supplied buffer large enough?
663 if (cbBuf
< *pcbNeeded
)
665 dwErrorCode
= ERROR_INSUFFICIENT_BUFFER
;
669 // Copy the path to the "prtprocs" directory into pPrintProcessorInfo
670 CopyMemory(pwszDirectory
, wszSpoolDirectory
, cchSpoolDirectory
* sizeof(WCHAR
));
671 CopyMemory(&pwszDirectory
[cchSpoolDirectory
], wszPath
, cchPath
* sizeof(WCHAR
));
673 // Get the directory name from the registry.
674 dwErrorCode
= (DWORD
)RegQueryValueExW(hKey
, L
"Directory", NULL
, NULL
, (PBYTE
)&pwszDirectory
[cchSpoolDirectory
+ cchPath
], &cbDirectoryName
);
675 if (dwErrorCode
!= ERROR_SUCCESS
)
677 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode
);
681 // We've finished successfully!
682 dwErrorCode
= ERROR_SUCCESS
;
688 SetLastError(dwErrorCode
);
689 return (dwErrorCode
== ERROR_SUCCESS
);