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-2016 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.
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
;
42 dwErrorCode
= ERROR_INVALID_ENVIRONMENT
;
46 // Construct the registry key of the demanded environment.
47 cchEnvironment
= wcslen(pEnvironment
);
48 pwszEnvironmentKey
= DllAllocSplMem((cchEnvironmentsKey
+ cchEnvironment
+ 1) * sizeof(WCHAR
));
49 if (!pwszEnvironmentKey
)
51 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
55 CopyMemory(pwszEnvironmentKey
, wszEnvironmentsKey
, cchEnvironmentsKey
* sizeof(WCHAR
));
56 CopyMemory(&pwszEnvironmentKey
[cchEnvironmentsKey
], pEnvironment
, (cchEnvironment
+ 1) * sizeof(WCHAR
));
58 // Open the registry key.
59 dwErrorCode
= (DWORD
)RegOpenKeyExW(HKEY_LOCAL_MACHINE
, pwszEnvironmentKey
, 0, KEY_READ
, hKey
);
60 if (dwErrorCode
== ERROR_FILE_NOT_FOUND
)
62 dwErrorCode
= ERROR_INVALID_ENVIRONMENT
;
65 else if (dwErrorCode
!= ERROR_SUCCESS
)
67 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
72 if (pwszEnvironmentKey
)
73 DllFreeSplMem(pwszEnvironmentKey
);
79 FindDatatype(const PLOCAL_PRINT_PROCESSOR pPrintProcessor
, PCWSTR pwszDatatype
)
82 PDATATYPES_INFO_1W pCurrentDatatype
= pPrintProcessor
->pDatatypesInfo1
;
87 for (i
= 0; i
< pPrintProcessor
->dwDatatypeCount
; i
++)
89 if (wcsicmp(pCurrentDatatype
->pName
, pwszDatatype
) == 0)
98 PLOCAL_PRINT_PROCESSOR
99 FindPrintProcessor(PCWSTR pwszName
)
102 PLOCAL_PRINT_PROCESSOR pPrintProcessor
;
107 for (pEntry
= _PrintProcessorList
.Flink
; pEntry
!= &_PrintProcessorList
; pEntry
= pEntry
->Flink
)
109 pPrintProcessor
= CONTAINING_RECORD(pEntry
, LOCAL_PRINT_PROCESSOR
, Entry
);
111 if (wcsicmp(pPrintProcessor
->pwszName
, pwszName
) == 0)
112 return pPrintProcessor
;
119 * @name InitializePrintProcessorList
121 * Initializes a singly linked list of locally available Print Processors.
124 InitializePrintProcessorList()
128 DWORD cchPrintProcessorPath
;
130 DWORD cchPrintProcessorName
;
134 HINSTANCE hinstPrintProcessor
;
137 HKEY hSubSubKey
= NULL
;
138 PLOCAL_PRINT_PROCESSOR pPrintProcessor
= NULL
;
139 WCHAR wszFileName
[MAX_PATH
];
140 WCHAR wszPrintProcessorPath
[MAX_PATH
];
142 // Initialize an empty list for our Print Processors.
143 InitializeListHead(&_PrintProcessorList
);
145 // Prepare the path to the Print Processor directory.
146 if (!LocalGetPrintProcessorDirectory(NULL
, (PWSTR
)wszCurrentEnvironment
, 1, (PBYTE
)wszPrintProcessorPath
, sizeof(wszPrintProcessorPath
), &cchPrintProcessorPath
))
148 dwErrorCode
= GetLastError();
152 // LocalGetPrintProcessorDirectory returns the number of copied bytes. Convert this into a number of characters without the terminating null-character.
153 cchPrintProcessorPath
/= sizeof(WCHAR
);
154 --cchPrintProcessorPath
;
156 // Append a trailing backslash.
157 wszPrintProcessorPath
[cchPrintProcessorPath
] = L
'\\';
158 ++cchPrintProcessorPath
;
160 // Open the environment registry key.
161 dwErrorCode
= _OpenEnvironment(wszCurrentEnvironment
, &hKey
);
162 if (dwErrorCode
!= ERROR_SUCCESS
)
164 ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode
);
168 // Open the "Print Processors" subkey.
169 dwErrorCode
= (DWORD
)RegOpenKeyExW(hKey
, L
"Print Processors", 0, KEY_READ
, &hSubKey
);
170 if (dwErrorCode
!= ERROR_SUCCESS
)
172 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
176 // Get the number of Print Processors and maximum sub key length.
177 dwErrorCode
= (DWORD
)RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwSubKeys
, &cchMaxSubKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
178 if (dwErrorCode
!= ERROR_SUCCESS
)
180 ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode
);
184 // Loop through all available local Print Processors.
185 for (i
= 0; i
< dwSubKeys
; i
++)
187 // Cleanup tasks from the previous run
190 RegCloseKey(hSubSubKey
);
196 if (pPrintProcessor
->pwszName
)
197 DllFreeSplStr(pPrintProcessor
->pwszName
);
199 if (pPrintProcessor
->pDatatypesInfo1
)
200 DllFreeSplMem(pPrintProcessor
->pDatatypesInfo1
);
202 DllFreeSplMem(pPrintProcessor
);
203 pPrintProcessor
= NULL
;
206 // Create a new LOCAL_PRINT_PROCESSOR structure for it.
207 pPrintProcessor
= DllAllocSplMem(sizeof(LOCAL_PRINT_PROCESSOR
));
208 if (!pPrintProcessor
)
210 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
211 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
215 // Allocate memory for the Print Monitor Name.
216 pPrintProcessor
->pwszName
= DllAllocSplMem((cchMaxSubKey
+ 1) * sizeof(WCHAR
));
217 if (!pPrintProcessor
->pwszName
)
219 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
220 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
224 // Get the name of this Print Processor.
225 cchPrintProcessorName
= cchMaxSubKey
+ 1;
226 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, pPrintProcessor
->pwszName
, &cchPrintProcessorName
, NULL
, NULL
, NULL
, NULL
);
227 if (dwErrorCode
!= ERROR_SUCCESS
)
229 ERR("RegEnumKeyExW failed with status %ld!\n", dwErrorCode
);
233 // Open this Print Processor's registry key.
234 dwErrorCode
= (DWORD
)RegOpenKeyExW(hSubKey
, pPrintProcessor
->pwszName
, 0, KEY_READ
, &hSubSubKey
);
235 if (dwErrorCode
!= ERROR_SUCCESS
)
237 ERR("RegOpenKeyExW failed for Print Processor \"%S\" with status %lu!\n", pPrintProcessor
->pwszName
, dwErrorCode
);
241 // Get the file name of the Print Processor.
242 cbFileName
= sizeof(wszFileName
);
243 dwErrorCode
= (DWORD
)RegQueryValueExW(hSubSubKey
, L
"Driver", NULL
, NULL
, (PBYTE
)wszFileName
, &cbFileName
);
244 if (dwErrorCode
!= ERROR_SUCCESS
)
246 ERR("RegQueryValueExW failed for Print Processor \"%S\" with status %lu!\n", pPrintProcessor
->pwszName
, dwErrorCode
);
250 // Verify that our buffer is large enough.
251 if (cchPrintProcessorPath
+ cbFileName
/ sizeof(WCHAR
) > MAX_PATH
)
253 ERR("Print Processor directory \"%S\" for Print Processor \"%S\" is too long!\n", wszFileName
, pPrintProcessor
->pwszName
);
257 // Construct the full path to the Print Processor.
258 CopyMemory(&wszPrintProcessorPath
[cchPrintProcessorPath
], wszFileName
, cbFileName
);
261 hinstPrintProcessor
= LoadLibraryW(wszPrintProcessorPath
);
262 if (!hinstPrintProcessor
)
264 ERR("LoadLibraryW failed for \"%S\" with error %lu!\n", wszPrintProcessorPath
, GetLastError());
268 // Get and verify all its function pointers.
269 pPrintProcessor
->pfnClosePrintProcessor
= (PClosePrintProcessor
)GetProcAddress(hinstPrintProcessor
, "ClosePrintProcessor");
270 if (!pPrintProcessor
->pfnClosePrintProcessor
)
272 ERR("Print Processor \"%S\" exports no ClosePrintProcessor!\n", wszPrintProcessorPath
);
276 pPrintProcessor
->pfnControlPrintProcessor
= (PControlPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "ControlPrintProcessor");
277 if (!pPrintProcessor
->pfnControlPrintProcessor
)
279 ERR("Print Processor \"%S\" exports no ControlPrintProcessor!\n", wszPrintProcessorPath
);
283 pPrintProcessor
->pfnEnumPrintProcessorDatatypesW
= (PEnumPrintProcessorDatatypesW
)GetProcAddress(hinstPrintProcessor
, "EnumPrintProcessorDatatypesW");
284 if (!pPrintProcessor
->pfnEnumPrintProcessorDatatypesW
)
286 ERR("Print Processor \"%S\" exports no EnumPrintProcessorDatatypesW!\n", wszPrintProcessorPath
);
290 pPrintProcessor
->pfnGetPrintProcessorCapabilities
= (PGetPrintProcessorCapabilities
)GetProcAddress(hinstPrintProcessor
, "GetPrintProcessorCapabilities");
291 if (!pPrintProcessor
->pfnGetPrintProcessorCapabilities
)
293 ERR("Print Processor \"%S\" exports no GetPrintProcessorCapabilities!\n", wszPrintProcessorPath
);
297 pPrintProcessor
->pfnOpenPrintProcessor
= (POpenPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "OpenPrintProcessor");
298 if (!pPrintProcessor
->pfnOpenPrintProcessor
)
300 ERR("Print Processor \"%S\" exports no OpenPrintProcessor!\n", wszPrintProcessorPath
);
304 pPrintProcessor
->pfnPrintDocumentOnPrintProcessor
= (PPrintDocumentOnPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "PrintDocumentOnPrintProcessor");
305 if (!pPrintProcessor
->pfnPrintDocumentOnPrintProcessor
)
307 ERR("Print Processor \"%S\" exports no PrintDocumentOnPrintProcessor!\n", wszPrintProcessorPath
);
311 // Get all supported datatypes.
312 pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(NULL
, NULL
, 1, NULL
, 0, &cbDatatypes
, &pPrintProcessor
->dwDatatypeCount
);
313 pPrintProcessor
->pDatatypesInfo1
= DllAllocSplMem(cbDatatypes
);
314 if (!pPrintProcessor
->pDatatypesInfo1
)
316 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
317 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
321 if (!pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(NULL
, NULL
, 1, (PBYTE
)pPrintProcessor
->pDatatypesInfo1
, cbDatatypes
, &cbDatatypes
, &pPrintProcessor
->dwDatatypeCount
))
323 ERR("EnumPrintProcessorDatatypesW failed for Print Processor \"%S\" with error %lu!\n", wszPrintProcessorPath
, GetLastError());
327 // Add the Print Processor to the list.
328 InsertTailList(&_PrintProcessorList
, &pPrintProcessor
->Entry
);
330 // Don't let the cleanup routines free this.
331 pPrintProcessor
= NULL
;
334 dwErrorCode
= ERROR_SUCCESS
;
339 RegCloseKey(hSubSubKey
);
343 if (pPrintProcessor
->pwszName
)
344 DllFreeSplStr(pPrintProcessor
->pwszName
);
346 if (pPrintProcessor
->pDatatypesInfo1
)
347 DllFreeSplMem(pPrintProcessor
->pDatatypesInfo1
);
349 DllFreeSplMem(pPrintProcessor
);
354 RegCloseKey(hSubKey
);
359 SetLastError(dwErrorCode
);
360 return (dwErrorCode
== ERROR_SUCCESS
);
364 * @name LocalEnumPrintProcessorDatatypes
366 * Obtains an array of all datatypes supported by a particular Print Processor.
367 * Print Provider function for EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW.
370 * Server Name. Ignored here, because every caller of LocalEnumPrintProcessorDatatypes is interested in the local directory.
372 * @param pPrintProcessorName
373 * The (case-insensitive) name of the Print Processor to query.
376 * The level of the structure supplied through pDatatypes. This must be 1.
379 * Pointer to the buffer that receives an array of DATATYPES_INFO_1W structures.
380 * Can be NULL if you just want to know the required size of the buffer.
383 * Size of the buffer you supplied for pDatatypes, in bytes.
386 * Pointer to a variable that receives the required size of the buffer for pDatatypes, in bytes.
387 * This parameter mustn't be NULL!
390 * Pointer to a variable that receives the number of elements of the DATATYPES_INFO_1W array.
391 * This parameter mustn't be NULL!
394 * TRUE if we successfully copied the array into pDatatypes, FALSE otherwise.
395 * A more specific error code can be obtained through GetLastError.
398 LocalEnumPrintProcessorDatatypes(LPWSTR pName
, LPWSTR pPrintProcessorName
, DWORD Level
, LPBYTE pDatatypes
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
)
401 PLOCAL_PRINT_PROCESSOR pPrintProcessor
;
406 dwErrorCode
= ERROR_INVALID_LEVEL
;
410 // Try to find the Print Processor.
411 pPrintProcessor
= FindPrintProcessor(pPrintProcessorName
);
412 if (!pPrintProcessor
)
414 dwErrorCode
= ERROR_UNKNOWN_PRINTPROCESSOR
;
418 // Call its EnumPrintProcessorDatatypesW function.
419 if (pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(pName
, pPrintProcessorName
, Level
, pDatatypes
, cbBuf
, pcbNeeded
, pcReturned
))
420 dwErrorCode
= ERROR_SUCCESS
;
422 dwErrorCode
= GetLastError();
425 SetLastError(dwErrorCode
);
426 return (dwErrorCode
== ERROR_SUCCESS
);
430 * @name LocalEnumPrintProcessors
432 * Obtains an array of all available Print Processors on this computer.
433 * Print Provider function for EnumPrintProcessorsA/EnumPrintProcessorsW.
436 * Server Name. Ignored here, because every caller of LocalEnumPrintProcessors is interested in the local directory.
438 * @param pEnvironment
439 * One of the predefined operating system and architecture "environment" strings (like "Windows NT x86").
440 * Alternatively, NULL to output the Print Processor directory of the current environment.
443 * The level of the structure supplied through pPrintProcessorInfo. This must be 1.
445 * @param pPrintProcessorInfo
446 * Pointer to the buffer that receives an array of PRINTPROCESSOR_INFO_1W structures.
447 * Can be NULL if you just want to know the required size of the buffer.
450 * Size of the buffer you supplied for pPrintProcessorInfo, in bytes.
453 * Pointer to a variable that receives the required size of the buffer for pPrintProcessorInfo, in bytes.
454 * This parameter mustn't be NULL!
457 * Pointer to a variable that receives the number of elements of the PRINTPROCESSOR_INFO_1W array.
458 * This parameter mustn't be NULL!
461 * TRUE if we successfully copied the array into pPrintProcessorInfo, FALSE otherwise.
462 * A more specific error code can be obtained through GetLastError.
465 LocalEnumPrintProcessors(LPWSTR pName
, LPWSTR pEnvironment
, DWORD Level
, LPBYTE pPrintProcessorInfo
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
)
468 DWORD cchPrintProcessor
;
470 DWORD dwPrintProcessorCount
;
474 PBYTE pCurrentOutputPrintProcessor
;
475 PBYTE pCurrentOutputPrintProcessorInfo
;
476 PRINTPROCESSOR_INFO_1W PrintProcessorInfo1
;
477 PWSTR pwszTemp
= NULL
;
482 dwErrorCode
= ERROR_INVALID_LEVEL
;
486 if (!pcbNeeded
|| !pcReturned
)
488 // This error is also caught by RPC and returned as RPC_X_NULL_REF_POINTER.
489 dwErrorCode
= ERROR_INVALID_PARAMETER
;
493 // Verify pEnvironment and open its registry key.
494 // We use the registry and not the PrintProcessorList here, because the caller may request information about a different environment.
495 dwErrorCode
= _OpenEnvironment(pEnvironment
, &hKey
);
496 if (dwErrorCode
!= ERROR_SUCCESS
)
498 ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode
);
502 // Open the "Print Processors" subkey.
503 dwErrorCode
= (DWORD
)RegOpenKeyExW(hKey
, L
"Print Processors", 0, KEY_READ
, &hSubKey
);
504 if (dwErrorCode
!= ERROR_SUCCESS
)
506 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
510 // Get the number of Print Processors and maximum sub key length.
511 dwErrorCode
= (DWORD
)RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwPrintProcessorCount
, &cchMaxSubKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
512 if (dwErrorCode
!= ERROR_SUCCESS
)
514 ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode
);
518 // Allocate a temporary buffer to let RegEnumKeyExW succeed.
519 pwszTemp
= DllAllocSplMem((cchMaxSubKey
+ 1) * sizeof(WCHAR
));
522 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
523 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
527 // Determine the required size of the output buffer.
530 for (i
= 0; i
< dwPrintProcessorCount
; i
++)
532 // RegEnumKeyExW sucks! Unlike similar API functions, it only returns the actual numbers of characters copied when you supply a buffer large enough.
533 // So use pwszTemp with its size cchMaxSubKey for this.
534 cchPrintProcessor
= cchMaxSubKey
+ 1;
535 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, pwszTemp
, &cchPrintProcessor
, NULL
, NULL
, NULL
, NULL
);
536 if (dwErrorCode
!= ERROR_SUCCESS
)
538 ERR("RegEnumKeyExW failed with status %lu!\n", dwErrorCode
);
542 *pcbNeeded
+= sizeof(PRINTPROCESSOR_INFO_1W
) + (cchPrintProcessor
+ 1) * sizeof(WCHAR
);
545 // Check if the supplied buffer is large enough.
546 if (cbBuf
< *pcbNeeded
)
548 dwErrorCode
= ERROR_INSUFFICIENT_BUFFER
;
552 // Put the Print Processor strings right after the last PRINTPROCESSOR_INFO_1W structure.
553 pCurrentOutputPrintProcessorInfo
= pPrintProcessorInfo
;
554 pCurrentOutputPrintProcessor
= pPrintProcessorInfo
+ dwPrintProcessorCount
* sizeof(PRINTPROCESSOR_INFO_1W
);
556 // Copy over all Print Processors.
557 for (i
= 0; i
< dwPrintProcessorCount
; i
++)
559 // This isn't really correct, but doesn't cause any harm, because we've extensively checked the size of the supplied buffer above.
560 cchPrintProcessor
= cchMaxSubKey
+ 1;
562 // Copy the Print Processor name.
563 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, (PWSTR
)pCurrentOutputPrintProcessor
, &cchPrintProcessor
, NULL
, NULL
, NULL
, NULL
);
564 if (dwErrorCode
!= ERROR_SUCCESS
)
566 ERR("RegEnumKeyExW failed with status %lu!\n", dwErrorCode
);
570 // Fill and copy the PRINTPROCESSOR_INFO_1W structure belonging to this Print Processor.
571 PrintProcessorInfo1
.pName
= (PWSTR
)pCurrentOutputPrintProcessor
;
572 CopyMemory(pCurrentOutputPrintProcessorInfo
, &PrintProcessorInfo1
, sizeof(PRINTPROCESSOR_INFO_1W
));
574 // Advance to the next PRINTPROCESSOR_INFO_1W location and string location in the output buffer.
575 pCurrentOutputPrintProcessor
+= (cchPrintProcessor
+ 1) * sizeof(WCHAR
);
576 pCurrentOutputPrintProcessorInfo
+= sizeof(PRINTPROCESSOR_INFO_1W
);
579 // We've finished successfully!
580 *pcReturned
= dwPrintProcessorCount
;
581 dwErrorCode
= ERROR_SUCCESS
;
585 DllFreeSplMem(pwszTemp
);
588 RegCloseKey(hSubKey
);
593 SetLastError(dwErrorCode
);
594 return (dwErrorCode
== ERROR_SUCCESS
);
598 * @name LocalGetPrintProcessorDirectory
600 * Obtains the path to the local Print Processor directory.
601 * Print Provider function for GetPrintProcessorDirectoryA/GetPrintProcessorDirectoryW.
604 * Server Name. Ignored here, because every caller of LocalGetPrintProcessorDirectory is interested in the local directory.
606 * @param pEnvironment
607 * One of the predefined operating system and architecture "environment" strings (like "Windows NT x86").
610 * The level of the (non-existing) structure supplied through pPrintProcessorInfo. This must be 1.
612 * @param pPrintProcessorInfo
613 * Pointer to the buffer that receives the full path to the Print Processor directory.
614 * Can be NULL if you just want to know the required size of the buffer.
617 * Size of the buffer you supplied for pPrintProcessorInfo, in bytes.
620 * Pointer to a variable that receives the required size of the buffer for pPrintProcessorInfo, in bytes.
621 * This parameter mustn't be NULL!
624 * TRUE if we successfully copied the directory into pPrintProcessorInfo, FALSE otherwise.
625 * A more specific error code can be obtained through GetLastError.
628 LocalGetPrintProcessorDirectory(PWSTR pName
, PWSTR pEnvironment
, DWORD Level
, PBYTE pPrintProcessorInfo
, DWORD cbBuf
, PDWORD pcbNeeded
)
630 const WCHAR wszPath
[] = L
"\\PRTPROCS\\";
631 const DWORD cchPath
= _countof(wszPath
) - 1;
633 DWORD cbDirectoryName
;
636 PWSTR pwszDirectory
= (PWSTR
)pPrintProcessorInfo
;
638 // Verify pEnvironment and open its registry key.
639 dwErrorCode
= _OpenEnvironment(pEnvironment
, &hKey
);
640 if (dwErrorCode
!= ERROR_SUCCESS
)
642 ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode
);
646 // Determine the size of the required buffer.
647 dwErrorCode
= (DWORD
)RegQueryValueExW(hKey
, L
"Directory", NULL
, NULL
, NULL
, &cbDirectoryName
);
648 if (dwErrorCode
!= ERROR_SUCCESS
)
650 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode
);
654 *pcbNeeded
= (cchSpoolDirectory
+ cchPath
) * sizeof(WCHAR
) + cbDirectoryName
;
656 // Is the supplied buffer large enough?
657 if (cbBuf
< *pcbNeeded
)
659 dwErrorCode
= ERROR_INSUFFICIENT_BUFFER
;
663 // Copy the path to the "prtprocs" directory into pPrintProcessorInfo
664 CopyMemory(pwszDirectory
, wszSpoolDirectory
, cchSpoolDirectory
* sizeof(WCHAR
));
665 CopyMemory(&pwszDirectory
[cchSpoolDirectory
], wszPath
, cchPath
* sizeof(WCHAR
));
667 // Get the directory name from the registry.
668 dwErrorCode
= (DWORD
)RegQueryValueExW(hKey
, L
"Directory", NULL
, NULL
, (PBYTE
)&pwszDirectory
[cchSpoolDirectory
+ cchPath
], &cbDirectoryName
);
669 if (dwErrorCode
!= ERROR_SUCCESS
)
671 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode
);
675 // We've finished successfully!
676 dwErrorCode
= ERROR_SUCCESS
;
682 SetLastError(dwErrorCode
);
683 return (dwErrorCode
== ERROR_SUCCESS
);