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
;
84 for (i
= 0; i
< pPrintProcessor
->dwDatatypeCount
; i
++)
86 if (wcsicmp(pCurrentDatatype
->pName
, pwszDatatype
) == 0)
95 PLOCAL_PRINT_PROCESSOR
96 FindPrintProcessor(PCWSTR pwszName
)
99 PLOCAL_PRINT_PROCESSOR pPrintProcessor
;
104 for (pEntry
= _PrintProcessorList
.Flink
; pEntry
!= &_PrintProcessorList
; pEntry
= pEntry
->Flink
)
106 pPrintProcessor
= CONTAINING_RECORD(pEntry
, LOCAL_PRINT_PROCESSOR
, Entry
);
108 if (wcsicmp(pPrintProcessor
->pwszName
, pwszName
) == 0)
109 return pPrintProcessor
;
116 * @name InitializePrintProcessorList
118 * Initializes a singly linked list of locally available Print Processors.
121 InitializePrintProcessorList()
125 DWORD cchPrintProcessorPath
;
127 DWORD cchPrintProcessorName
;
131 HINSTANCE hinstPrintProcessor
;
134 HKEY hSubSubKey
= NULL
;
135 PLOCAL_PRINT_PROCESSOR pPrintProcessor
= NULL
;
136 WCHAR wszFileName
[MAX_PATH
];
137 WCHAR wszPrintProcessorPath
[MAX_PATH
];
139 // Initialize an empty list for our Print Processors.
140 InitializeListHead(&_PrintProcessorList
);
142 // Prepare the path to the Print Processor directory.
143 if (!LocalGetPrintProcessorDirectory(NULL
, NULL
, 1, (PBYTE
)wszPrintProcessorPath
, sizeof(wszPrintProcessorPath
), &cchPrintProcessorPath
))
145 dwErrorCode
= GetLastError();
149 // LocalGetPrintProcessorDirectory returns the number of copied bytes. Convert this into a number of characters without the terminating null-character.
150 cchPrintProcessorPath
/= sizeof(WCHAR
);
151 --cchPrintProcessorPath
;
153 // Append a trailing backslash.
154 wszPrintProcessorPath
[cchPrintProcessorPath
] = L
'\\';
155 ++cchPrintProcessorPath
;
157 // Open the environment registry key.
158 dwErrorCode
= _OpenEnvironment(NULL
, &hKey
);
159 if (dwErrorCode
!= ERROR_SUCCESS
)
161 ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode
);
165 // Open the "Print Processors" subkey.
166 dwErrorCode
= (DWORD
)RegOpenKeyExW(hKey
, L
"Print Processors", 0, KEY_READ
, &hSubKey
);
167 if (dwErrorCode
!= ERROR_SUCCESS
)
169 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
173 // Get the number of Print Processors and maximum sub key length.
174 dwErrorCode
= (DWORD
)RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwSubKeys
, &cchMaxSubKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
175 if (dwErrorCode
!= ERROR_SUCCESS
)
177 ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode
);
181 // Loop through all available local Print Processors.
182 for (i
= 0; i
< dwSubKeys
; i
++)
184 // Cleanup tasks from the previous run
187 RegCloseKey(hSubSubKey
);
193 if (pPrintProcessor
->pwszName
)
194 DllFreeSplStr(pPrintProcessor
->pwszName
);
196 if (pPrintProcessor
->pDatatypesInfo1
)
197 DllFreeSplMem(pPrintProcessor
->pDatatypesInfo1
);
199 DllFreeSplMem(pPrintProcessor
);
200 pPrintProcessor
= NULL
;
203 // Create a new LOCAL_PRINT_PROCESSOR structure for it.
204 pPrintProcessor
= DllAllocSplMem(sizeof(LOCAL_PRINT_PROCESSOR
));
205 if (!pPrintProcessor
)
207 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
208 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
212 // Allocate memory for the Print Monitor Name.
213 pPrintProcessor
->pwszName
= DllAllocSplMem((cchMaxSubKey
+ 1) * sizeof(WCHAR
));
214 if (!pPrintProcessor
->pwszName
)
216 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
217 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
221 // Get the name of this Print Processor.
222 cchPrintProcessorName
= cchMaxSubKey
+ 1;
223 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, pPrintProcessor
->pwszName
, &cchPrintProcessorName
, NULL
, NULL
, NULL
, NULL
);
224 if (dwErrorCode
!= ERROR_SUCCESS
)
226 ERR("RegEnumKeyExW failed with status %ld!\n", dwErrorCode
);
230 // Open this Print Processor's registry key.
231 dwErrorCode
= (DWORD
)RegOpenKeyExW(hSubKey
, pPrintProcessor
->pwszName
, 0, KEY_READ
, &hSubSubKey
);
232 if (dwErrorCode
!= ERROR_SUCCESS
)
234 ERR("RegOpenKeyExW failed for Print Processor \"%S\" with status %lu!\n", pPrintProcessor
->pwszName
, dwErrorCode
);
238 // Get the file name of the Print Processor.
239 cbFileName
= sizeof(wszFileName
);
240 dwErrorCode
= (DWORD
)RegQueryValueExW(hSubSubKey
, L
"Driver", NULL
, NULL
, (PBYTE
)wszFileName
, &cbFileName
);
241 if (dwErrorCode
!= ERROR_SUCCESS
)
243 ERR("RegQueryValueExW failed for Print Processor \"%S\" with status %lu!\n", pPrintProcessor
->pwszName
, dwErrorCode
);
247 // Verify that our buffer is large enough.
248 if (cchPrintProcessorPath
+ cbFileName
/ sizeof(WCHAR
) > MAX_PATH
)
250 ERR("Print Processor directory \"%S\" for Print Processor \"%S\" is too long!\n", wszFileName
, pPrintProcessor
->pwszName
);
254 // Construct the full path to the Print Processor.
255 CopyMemory(&wszPrintProcessorPath
[cchPrintProcessorPath
], wszFileName
, cbFileName
);
258 hinstPrintProcessor
= LoadLibraryW(wszPrintProcessorPath
);
259 if (!hinstPrintProcessor
)
261 ERR("LoadLibraryW failed for \"%S\" with error %lu!\n", wszPrintProcessorPath
, GetLastError());
265 // Get and verify all its function pointers.
266 pPrintProcessor
->pfnClosePrintProcessor
= (PClosePrintProcessor
)GetProcAddress(hinstPrintProcessor
, "ClosePrintProcessor");
267 if (!pPrintProcessor
->pfnClosePrintProcessor
)
269 ERR("Print Processor \"%S\" exports no ClosePrintProcessor!\n", wszPrintProcessorPath
);
273 pPrintProcessor
->pfnControlPrintProcessor
= (PControlPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "ControlPrintProcessor");
274 if (!pPrintProcessor
->pfnControlPrintProcessor
)
276 ERR("Print Processor \"%S\" exports no ControlPrintProcessor!\n", wszPrintProcessorPath
);
280 pPrintProcessor
->pfnEnumPrintProcessorDatatypesW
= (PEnumPrintProcessorDatatypesW
)GetProcAddress(hinstPrintProcessor
, "EnumPrintProcessorDatatypesW");
281 if (!pPrintProcessor
->pfnEnumPrintProcessorDatatypesW
)
283 ERR("Print Processor \"%S\" exports no EnumPrintProcessorDatatypesW!\n", wszPrintProcessorPath
);
287 pPrintProcessor
->pfnGetPrintProcessorCapabilities
= (PGetPrintProcessorCapabilities
)GetProcAddress(hinstPrintProcessor
, "GetPrintProcessorCapabilities");
288 if (!pPrintProcessor
->pfnGetPrintProcessorCapabilities
)
290 ERR("Print Processor \"%S\" exports no GetPrintProcessorCapabilities!\n", wszPrintProcessorPath
);
294 pPrintProcessor
->pfnOpenPrintProcessor
= (POpenPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "OpenPrintProcessor");
295 if (!pPrintProcessor
->pfnOpenPrintProcessor
)
297 ERR("Print Processor \"%S\" exports no OpenPrintProcessor!\n", wszPrintProcessorPath
);
301 pPrintProcessor
->pfnPrintDocumentOnPrintProcessor
= (PPrintDocumentOnPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "PrintDocumentOnPrintProcessor");
302 if (!pPrintProcessor
->pfnPrintDocumentOnPrintProcessor
)
304 ERR("Print Processor \"%S\" exports no PrintDocumentOnPrintProcessor!\n", wszPrintProcessorPath
);
308 // Get all supported datatypes.
309 pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(NULL
, NULL
, 1, NULL
, 0, &cbDatatypes
, &pPrintProcessor
->dwDatatypeCount
);
310 pPrintProcessor
->pDatatypesInfo1
= DllAllocSplMem(cbDatatypes
);
311 if (!pPrintProcessor
->pDatatypesInfo1
)
313 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
314 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
318 if (!pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(NULL
, NULL
, 1, (PBYTE
)pPrintProcessor
->pDatatypesInfo1
, cbDatatypes
, &cbDatatypes
, &pPrintProcessor
->dwDatatypeCount
))
320 ERR("EnumPrintProcessorDatatypesW failed for Print Processor \"%S\" with error %lu!\n", wszPrintProcessorPath
, GetLastError());
324 // Add the Print Processor to the list.
325 InsertTailList(&_PrintProcessorList
, &pPrintProcessor
->Entry
);
327 // Don't let the cleanup routines free this.
328 pPrintProcessor
= NULL
;
331 dwErrorCode
= ERROR_SUCCESS
;
336 RegCloseKey(hSubSubKey
);
340 if (pPrintProcessor
->pwszName
)
341 DllFreeSplStr(pPrintProcessor
->pwszName
);
343 if (pPrintProcessor
->pDatatypesInfo1
)
344 DllFreeSplMem(pPrintProcessor
->pDatatypesInfo1
);
346 DllFreeSplMem(pPrintProcessor
);
351 RegCloseKey(hSubKey
);
356 SetLastError(dwErrorCode
);
357 return (dwErrorCode
== ERROR_SUCCESS
);
361 * @name LocalEnumPrintProcessorDatatypes
363 * Obtains an array of all datatypes supported by a particular Print Processor.
364 * Print Provider function for EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW.
367 * Server Name. Ignored here, because every caller of LocalEnumPrintProcessorDatatypes is interested in the local directory.
369 * @param pPrintProcessorName
370 * The (case-insensitive) name of the Print Processor to query.
373 * The level of the structure supplied through pDatatypes. This must be 1.
376 * Pointer to the buffer that receives an array of DATATYPES_INFO_1W structures.
377 * Can be NULL if you just want to know the required size of the buffer.
380 * Size of the buffer you supplied for pDatatypes, in bytes.
383 * Pointer to a variable that receives the required size of the buffer for pDatatypes, in bytes.
384 * This parameter mustn't be NULL!
387 * Pointer to a variable that receives the number of elements of the DATATYPES_INFO_1W array.
388 * This parameter mustn't be NULL!
391 * TRUE if we successfully copied the array into pDatatypes, FALSE otherwise.
392 * A more specific error code can be obtained through GetLastError.
395 LocalEnumPrintProcessorDatatypes(LPWSTR pName
, LPWSTR pPrintProcessorName
, DWORD Level
, LPBYTE pDatatypes
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
)
398 PLOCAL_PRINT_PROCESSOR pPrintProcessor
;
403 dwErrorCode
= ERROR_INVALID_LEVEL
;
407 // Try to find the Print Processor.
408 pPrintProcessor
= FindPrintProcessor(pPrintProcessorName
);
409 if (!pPrintProcessor
)
411 dwErrorCode
= ERROR_UNKNOWN_PRINTPROCESSOR
;
415 // Call its EnumPrintProcessorDatatypesW function.
416 if (pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(pName
, pPrintProcessorName
, Level
, pDatatypes
, cbBuf
, pcbNeeded
, pcReturned
))
417 dwErrorCode
= ERROR_SUCCESS
;
419 dwErrorCode
= GetLastError();
422 SetLastError(dwErrorCode
);
423 return (dwErrorCode
== ERROR_SUCCESS
);
427 * @name LocalEnumPrintProcessors
429 * Obtains an array of all available Print Processors on this computer.
430 * Print Provider function for EnumPrintProcessorsA/EnumPrintProcessorsW.
433 * Server Name. Ignored here, because every caller of LocalEnumPrintProcessors is interested in the local directory.
435 * @param pEnvironment
436 * One of the predefined operating system and architecture "environment" strings (like "Windows NT x86").
437 * Alternatively, NULL to output the Print Processor directory of the current environment.
440 * The level of the structure supplied through pPrintProcessorInfo. This must be 1.
442 * @param pPrintProcessorInfo
443 * Pointer to the buffer that receives an array of PRINTPROCESSOR_INFO_1W structures.
444 * Can be NULL if you just want to know the required size of the buffer.
447 * Size of the buffer you supplied for pPrintProcessorInfo, in bytes.
450 * Pointer to a variable that receives the required size of the buffer for pPrintProcessorInfo, in bytes.
451 * This parameter mustn't be NULL!
454 * Pointer to a variable that receives the number of elements of the PRINTPROCESSOR_INFO_1W array.
455 * This parameter mustn't be NULL!
458 * TRUE if we successfully copied the array into pPrintProcessorInfo, FALSE otherwise.
459 * A more specific error code can be obtained through GetLastError.
462 LocalEnumPrintProcessors(LPWSTR pName
, LPWSTR pEnvironment
, DWORD Level
, LPBYTE pPrintProcessorInfo
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
)
465 DWORD cchPrintProcessor
;
467 DWORD dwPrintProcessorCount
;
471 PBYTE pCurrentOutputPrintProcessor
;
472 PBYTE pCurrentOutputPrintProcessorInfo
;
473 PRINTPROCESSOR_INFO_1W PrintProcessorInfo1
;
474 PWSTR pwszTemp
= NULL
;
479 dwErrorCode
= ERROR_INVALID_LEVEL
;
483 if (!pcbNeeded
|| !pcReturned
)
485 // This error is also caught by RPC and returned as RPC_X_NULL_REF_POINTER.
486 dwErrorCode
= ERROR_INVALID_PARAMETER
;
490 // Verify pEnvironment and open its registry key.
491 // We use the registry and not the PrintProcessorList here, because the caller may request information about a different environment.
492 dwErrorCode
= _OpenEnvironment(pEnvironment
, &hKey
);
493 if (dwErrorCode
!= ERROR_SUCCESS
)
495 ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode
);
499 // Open the "Print Processors" subkey.
500 dwErrorCode
= (DWORD
)RegOpenKeyExW(hKey
, L
"Print Processors", 0, KEY_READ
, &hSubKey
);
501 if (dwErrorCode
!= ERROR_SUCCESS
)
503 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
507 // Get the number of Print Processors and maximum sub key length.
508 dwErrorCode
= (DWORD
)RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwPrintProcessorCount
, &cchMaxSubKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
509 if (dwErrorCode
!= ERROR_SUCCESS
)
511 ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode
);
515 // Allocate a temporary buffer to let RegEnumKeyExW succeed.
516 pwszTemp
= DllAllocSplMem((cchMaxSubKey
+ 1) * sizeof(WCHAR
));
519 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
520 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
524 // Determine the required size of the output buffer.
527 for (i
= 0; i
< dwPrintProcessorCount
; i
++)
529 // RegEnumKeyExW sucks! Unlike similar API functions, it only returns the actual numbers of characters copied when you supply a buffer large enough.
530 // So use pwszTemp with its size cchMaxSubKey for this.
531 cchPrintProcessor
= cchMaxSubKey
+ 1;
532 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, pwszTemp
, &cchPrintProcessor
, NULL
, NULL
, NULL
, NULL
);
533 if (dwErrorCode
!= ERROR_SUCCESS
)
535 ERR("RegEnumKeyExW failed with status %lu!\n", dwErrorCode
);
539 *pcbNeeded
+= sizeof(PRINTPROCESSOR_INFO_1W
) + (cchPrintProcessor
+ 1) * sizeof(WCHAR
);
542 // Check if the supplied buffer is large enough.
543 if (cbBuf
< *pcbNeeded
)
545 dwErrorCode
= ERROR_INSUFFICIENT_BUFFER
;
549 // Put the Print Processor strings right after the last PRINTPROCESSOR_INFO_1W structure.
550 pCurrentOutputPrintProcessorInfo
= pPrintProcessorInfo
;
551 pCurrentOutputPrintProcessor
= pPrintProcessorInfo
+ dwPrintProcessorCount
* sizeof(PRINTPROCESSOR_INFO_1W
);
553 // Copy over all Print Processors.
554 for (i
= 0; i
< dwPrintProcessorCount
; i
++)
556 // This isn't really correct, but doesn't cause any harm, because we've extensively checked the size of the supplied buffer above.
557 cchPrintProcessor
= cchMaxSubKey
+ 1;
559 // Copy the Print Processor name.
560 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, (PWSTR
)pCurrentOutputPrintProcessor
, &cchPrintProcessor
, NULL
, NULL
, NULL
, NULL
);
561 if (dwErrorCode
!= ERROR_SUCCESS
)
563 ERR("RegEnumKeyExW failed with status %lu!\n", dwErrorCode
);
567 // Fill and copy the PRINTPROCESSOR_INFO_1W structure belonging to this Print Processor.
568 PrintProcessorInfo1
.pName
= (PWSTR
)pCurrentOutputPrintProcessor
;
569 CopyMemory(pCurrentOutputPrintProcessorInfo
, &PrintProcessorInfo1
, sizeof(PRINTPROCESSOR_INFO_1W
));
571 // Advance to the next PRINTPROCESSOR_INFO_1W location and string location in the output buffer.
572 pCurrentOutputPrintProcessor
+= (cchPrintProcessor
+ 1) * sizeof(WCHAR
);
573 pCurrentOutputPrintProcessorInfo
+= sizeof(PRINTPROCESSOR_INFO_1W
);
576 // We've finished successfully!
577 *pcReturned
= dwPrintProcessorCount
;
578 dwErrorCode
= ERROR_SUCCESS
;
582 DllFreeSplMem(pwszTemp
);
585 RegCloseKey(hSubKey
);
590 SetLastError(dwErrorCode
);
591 return (dwErrorCode
== ERROR_SUCCESS
);
595 * @name LocalGetPrintProcessorDirectory
597 * Obtains the path to the local Print Processor directory.
598 * Print Provider function for GetPrintProcessorDirectoryA/GetPrintProcessorDirectoryW.
601 * Server Name. Ignored here, because every caller of LocalGetPrintProcessorDirectory is interested in the local directory.
603 * @param pEnvironment
604 * One of the predefined operating system and architecture "environment" strings (like "Windows NT x86").
605 * Alternatively, NULL to output the Print Processor directory of the current environment.
608 * The level of the (non-existing) structure supplied through pPrintProcessorInfo. This must be 1.
610 * @param pPrintProcessorInfo
611 * Pointer to the buffer that receives the full path to the Print Processor directory.
612 * Can be NULL if you just want to know the required size of the buffer.
615 * Size of the buffer you supplied for pPrintProcessorInfo, in bytes.
618 * Pointer to a variable that receives the required size of the buffer for pPrintProcessorInfo, in bytes.
619 * This parameter mustn't be NULL!
622 * TRUE if we successfully copied the directory into pPrintProcessorInfo, FALSE otherwise.
623 * A more specific error code can be obtained through GetLastError.
626 LocalGetPrintProcessorDirectory(PWSTR pName
, PWSTR pEnvironment
, DWORD Level
, PBYTE pPrintProcessorInfo
, DWORD cbBuf
, PDWORD pcbNeeded
)
628 const WCHAR wszPath
[] = L
"\\PRTPROCS\\";
629 const DWORD cchPath
= _countof(wszPath
) - 1;
631 DWORD cbDirectoryName
;
634 PWSTR pwszDirectory
= (PWSTR
)pPrintProcessorInfo
;
639 dwErrorCode
= ERROR_INVALID_LEVEL
;
645 // This error is also caught by RPC and returned as RPC_X_NULL_REF_POINTER.
646 dwErrorCode
= ERROR_INVALID_PARAMETER
;
650 // Verify pEnvironment and open its registry key.
651 dwErrorCode
= _OpenEnvironment(pEnvironment
, &hKey
);
652 if (dwErrorCode
!= ERROR_SUCCESS
)
654 ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode
);
658 // Determine the size of the required buffer.
659 dwErrorCode
= (DWORD
)RegQueryValueExW(hKey
, L
"Directory", NULL
, NULL
, NULL
, &cbDirectoryName
);
660 if (dwErrorCode
!= ERROR_SUCCESS
)
662 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode
);
666 *pcbNeeded
= (cchSpoolDirectory
+ cchPath
) * sizeof(WCHAR
) + cbDirectoryName
;
668 // Is the supplied buffer large enough?
669 if (cbBuf
< *pcbNeeded
)
671 dwErrorCode
= ERROR_INSUFFICIENT_BUFFER
;
675 // Copy the path to the "prtprocs" directory into pPrintProcessorInfo
676 CopyMemory(pwszDirectory
, wszSpoolDirectory
, cchSpoolDirectory
* sizeof(WCHAR
));
677 CopyMemory(&pwszDirectory
[cchSpoolDirectory
], wszPath
, cchPath
* sizeof(WCHAR
));
679 // Get the directory name from the registry.
680 dwErrorCode
= (DWORD
)RegQueryValueExW(hKey
, L
"Directory", NULL
, NULL
, (PBYTE
)&pwszDirectory
[cchSpoolDirectory
+ cchPath
], &cbDirectoryName
);
681 if (dwErrorCode
!= ERROR_SUCCESS
)
683 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode
);
687 // We've finished successfully!
688 dwErrorCode
= ERROR_SUCCESS
;
694 SetLastError(dwErrorCode
);
695 return (dwErrorCode
== ERROR_SUCCESS
);