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-2017 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 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
52 ERR("DllAllocSplMem failed!\n");
56 CopyMemory(pwszEnvironmentKey
, wszEnvironmentsKey
, cchEnvironmentsKey
* sizeof(WCHAR
));
57 CopyMemory(&pwszEnvironmentKey
[cchEnvironmentsKey
], pEnvironment
, (cchEnvironment
+ 1) * sizeof(WCHAR
));
59 // Open the registry key.
60 dwErrorCode
= (DWORD
)RegOpenKeyExW(HKEY_LOCAL_MACHINE
, pwszEnvironmentKey
, 0, KEY_READ
, hKey
);
61 if (dwErrorCode
== ERROR_FILE_NOT_FOUND
)
63 dwErrorCode
= ERROR_INVALID_ENVIRONMENT
;
66 else if (dwErrorCode
!= ERROR_SUCCESS
)
68 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
73 if (pwszEnvironmentKey
)
74 DllFreeSplMem(pwszEnvironmentKey
);
80 FindDatatype(const PLOCAL_PRINT_PROCESSOR pPrintProcessor
, PCWSTR pwszDatatype
)
83 PDATATYPES_INFO_1W pCurrentDatatype
= pPrintProcessor
->pDatatypesInfo1
;
88 for (i
= 0; i
< pPrintProcessor
->dwDatatypeCount
; i
++)
90 if (wcsicmp(pCurrentDatatype
->pName
, pwszDatatype
) == 0)
99 PLOCAL_PRINT_PROCESSOR
100 FindPrintProcessor(PCWSTR pwszName
)
103 PLOCAL_PRINT_PROCESSOR pPrintProcessor
;
108 for (pEntry
= _PrintProcessorList
.Flink
; pEntry
!= &_PrintProcessorList
; pEntry
= pEntry
->Flink
)
110 pPrintProcessor
= CONTAINING_RECORD(pEntry
, LOCAL_PRINT_PROCESSOR
, Entry
);
112 if (wcsicmp(pPrintProcessor
->pwszName
, pwszName
) == 0)
113 return pPrintProcessor
;
120 * @name InitializePrintProcessorList
122 * Initializes a singly linked list of locally available Print Processors.
125 InitializePrintProcessorList()
129 DWORD cchPrintProcessorPath
;
131 DWORD cchPrintProcessorName
;
135 HINSTANCE hinstPrintProcessor
;
138 HKEY hSubSubKey
= NULL
;
139 PLOCAL_PRINT_PROCESSOR pPrintProcessor
= NULL
;
140 WCHAR wszFileName
[MAX_PATH
];
141 WCHAR wszPrintProcessorPath
[MAX_PATH
];
143 // Initialize an empty list for our Print Processors.
144 InitializeListHead(&_PrintProcessorList
);
146 // Prepare the path to the Print Processor directory.
147 if (!LocalGetPrintProcessorDirectory(NULL
, (PWSTR
)wszCurrentEnvironment
, 1, (PBYTE
)wszPrintProcessorPath
, sizeof(wszPrintProcessorPath
), &cchPrintProcessorPath
))
149 dwErrorCode
= GetLastError();
153 // LocalGetPrintProcessorDirectory returns the number of copied bytes. Convert this into a number of characters without the terminating null-character.
154 cchPrintProcessorPath
/= sizeof(WCHAR
);
155 --cchPrintProcessorPath
;
157 // Append a trailing backslash.
158 wszPrintProcessorPath
[cchPrintProcessorPath
] = L
'\\';
159 ++cchPrintProcessorPath
;
161 // Open the environment registry key.
162 dwErrorCode
= _OpenEnvironment(wszCurrentEnvironment
, &hKey
);
163 if (dwErrorCode
!= ERROR_SUCCESS
)
166 // Open the "Print Processors" subkey.
167 dwErrorCode
= (DWORD
)RegOpenKeyExW(hKey
, L
"Print Processors", 0, KEY_READ
, &hSubKey
);
168 if (dwErrorCode
!= ERROR_SUCCESS
)
170 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
174 // Get the number of Print Processors and maximum sub key length.
175 dwErrorCode
= (DWORD
)RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwSubKeys
, &cchMaxSubKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
176 if (dwErrorCode
!= ERROR_SUCCESS
)
178 ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode
);
182 // Loop through all available local Print Processors.
183 for (i
= 0; i
< dwSubKeys
; i
++)
185 // Cleanup tasks from the previous run
188 RegCloseKey(hSubSubKey
);
194 if (pPrintProcessor
->pwszName
)
195 DllFreeSplStr(pPrintProcessor
->pwszName
);
197 if (pPrintProcessor
->pDatatypesInfo1
)
198 DllFreeSplMem(pPrintProcessor
->pDatatypesInfo1
);
200 DllFreeSplMem(pPrintProcessor
);
201 pPrintProcessor
= NULL
;
204 // Create a new LOCAL_PRINT_PROCESSOR structure for it.
205 pPrintProcessor
= DllAllocSplMem(sizeof(LOCAL_PRINT_PROCESSOR
));
206 if (!pPrintProcessor
)
208 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
209 ERR("DllAllocSplMem failed!\n");
213 // Allocate memory for the Print Monitor Name.
214 pPrintProcessor
->pwszName
= DllAllocSplMem((cchMaxSubKey
+ 1) * sizeof(WCHAR
));
215 if (!pPrintProcessor
->pwszName
)
217 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
218 ERR("DllAllocSplMem failed!\n");
222 // Get the name of this Print Processor.
223 cchPrintProcessorName
= cchMaxSubKey
+ 1;
224 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, pPrintProcessor
->pwszName
, &cchPrintProcessorName
, NULL
, NULL
, NULL
, NULL
);
225 if (dwErrorCode
!= ERROR_SUCCESS
)
227 ERR("RegEnumKeyExW failed with status %ld!\n", dwErrorCode
);
231 // Open this Print Processor's registry key.
232 dwErrorCode
= (DWORD
)RegOpenKeyExW(hSubKey
, pPrintProcessor
->pwszName
, 0, KEY_READ
, &hSubSubKey
);
233 if (dwErrorCode
!= ERROR_SUCCESS
)
235 ERR("RegOpenKeyExW failed for Print Processor \"%S\" with status %lu!\n", pPrintProcessor
->pwszName
, dwErrorCode
);
239 // Get the file name of the Print Processor.
240 cbFileName
= sizeof(wszFileName
);
241 dwErrorCode
= (DWORD
)RegQueryValueExW(hSubSubKey
, L
"Driver", NULL
, NULL
, (PBYTE
)wszFileName
, &cbFileName
);
242 if (dwErrorCode
!= ERROR_SUCCESS
)
244 ERR("RegQueryValueExW failed for Print Processor \"%S\" with status %lu!\n", pPrintProcessor
->pwszName
, dwErrorCode
);
248 // Verify that our buffer is large enough.
249 if (cchPrintProcessorPath
+ cbFileName
/ sizeof(WCHAR
) > MAX_PATH
)
251 ERR("Print Processor directory \"%S\" for Print Processor \"%S\" is too long!\n", wszFileName
, pPrintProcessor
->pwszName
);
255 // Construct the full path to the Print Processor.
256 CopyMemory(&wszPrintProcessorPath
[cchPrintProcessorPath
], wszFileName
, cbFileName
);
259 hinstPrintProcessor
= LoadLibraryW(wszPrintProcessorPath
);
260 if (!hinstPrintProcessor
)
262 ERR("LoadLibraryW failed for \"%S\" with error %lu!\n", wszPrintProcessorPath
, GetLastError());
266 // Get and verify all its function pointers.
267 pPrintProcessor
->pfnClosePrintProcessor
= (PClosePrintProcessor
)GetProcAddress(hinstPrintProcessor
, "ClosePrintProcessor");
268 if (!pPrintProcessor
->pfnClosePrintProcessor
)
270 ERR("Print Processor \"%S\" exports no ClosePrintProcessor!\n", wszPrintProcessorPath
);
274 pPrintProcessor
->pfnControlPrintProcessor
= (PControlPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "ControlPrintProcessor");
275 if (!pPrintProcessor
->pfnControlPrintProcessor
)
277 ERR("Print Processor \"%S\" exports no ControlPrintProcessor!\n", wszPrintProcessorPath
);
281 pPrintProcessor
->pfnEnumPrintProcessorDatatypesW
= (PEnumPrintProcessorDatatypesW
)GetProcAddress(hinstPrintProcessor
, "EnumPrintProcessorDatatypesW");
282 if (!pPrintProcessor
->pfnEnumPrintProcessorDatatypesW
)
284 ERR("Print Processor \"%S\" exports no EnumPrintProcessorDatatypesW!\n", wszPrintProcessorPath
);
288 pPrintProcessor
->pfnGetPrintProcessorCapabilities
= (PGetPrintProcessorCapabilities
)GetProcAddress(hinstPrintProcessor
, "GetPrintProcessorCapabilities");
289 if (!pPrintProcessor
->pfnGetPrintProcessorCapabilities
)
291 ERR("Print Processor \"%S\" exports no GetPrintProcessorCapabilities!\n", wszPrintProcessorPath
);
295 pPrintProcessor
->pfnOpenPrintProcessor
= (POpenPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "OpenPrintProcessor");
296 if (!pPrintProcessor
->pfnOpenPrintProcessor
)
298 ERR("Print Processor \"%S\" exports no OpenPrintProcessor!\n", wszPrintProcessorPath
);
302 pPrintProcessor
->pfnPrintDocumentOnPrintProcessor
= (PPrintDocumentOnPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "PrintDocumentOnPrintProcessor");
303 if (!pPrintProcessor
->pfnPrintDocumentOnPrintProcessor
)
305 ERR("Print Processor \"%S\" exports no PrintDocumentOnPrintProcessor!\n", wszPrintProcessorPath
);
309 // Get all supported datatypes.
310 pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(NULL
, NULL
, 1, NULL
, 0, &cbDatatypes
, &pPrintProcessor
->dwDatatypeCount
);
311 pPrintProcessor
->pDatatypesInfo1
= DllAllocSplMem(cbDatatypes
);
312 if (!pPrintProcessor
->pDatatypesInfo1
)
314 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
315 ERR("DllAllocSplMem failed!\n");
319 if (!pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(NULL
, NULL
, 1, (PBYTE
)pPrintProcessor
->pDatatypesInfo1
, cbDatatypes
, &cbDatatypes
, &pPrintProcessor
->dwDatatypeCount
))
321 ERR("EnumPrintProcessorDatatypesW failed for Print Processor \"%S\" with error %lu!\n", wszPrintProcessorPath
, GetLastError());
325 // Add the Print Processor to the list.
326 InsertTailList(&_PrintProcessorList
, &pPrintProcessor
->Entry
);
328 // Don't let the cleanup routines free this.
329 pPrintProcessor
= NULL
;
332 dwErrorCode
= ERROR_SUCCESS
;
337 RegCloseKey(hSubSubKey
);
341 if (pPrintProcessor
->pwszName
)
342 DllFreeSplStr(pPrintProcessor
->pwszName
);
344 if (pPrintProcessor
->pDatatypesInfo1
)
345 DllFreeSplMem(pPrintProcessor
->pDatatypesInfo1
);
347 DllFreeSplMem(pPrintProcessor
);
352 RegCloseKey(hSubKey
);
357 SetLastError(dwErrorCode
);
358 return (dwErrorCode
== ERROR_SUCCESS
);
362 * @name LocalEnumPrintProcessorDatatypes
364 * Obtains an array of all datatypes supported by a particular Print Processor.
365 * Print Provider function for EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW.
368 * Server Name. Ignored here, because every caller of LocalEnumPrintProcessorDatatypes is interested in the local directory.
370 * @param pPrintProcessorName
371 * The (case-insensitive) name of the Print Processor to query.
374 * The level of the structure supplied through pDatatypes. This must be 1.
377 * Pointer to the buffer that receives an array of DATATYPES_INFO_1W structures.
378 * Can be NULL if you just want to know the required size of the buffer.
381 * Size of the buffer you supplied for pDatatypes, in bytes.
384 * Pointer to a variable that receives the required size of the buffer for pDatatypes, in bytes.
385 * This parameter mustn't be NULL!
388 * Pointer to a variable that receives the number of elements of the DATATYPES_INFO_1W array.
389 * This parameter mustn't be NULL!
392 * TRUE if we successfully copied the array into pDatatypes, FALSE otherwise.
393 * A more specific error code can be obtained through GetLastError.
396 LocalEnumPrintProcessorDatatypes(LPWSTR pName
, LPWSTR pPrintProcessorName
, DWORD Level
, LPBYTE pDatatypes
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
)
399 PLOCAL_PRINT_PROCESSOR pPrintProcessor
;
404 dwErrorCode
= ERROR_INVALID_LEVEL
;
408 // Try to find the Print Processor.
409 pPrintProcessor
= FindPrintProcessor(pPrintProcessorName
);
410 if (!pPrintProcessor
)
412 dwErrorCode
= ERROR_UNKNOWN_PRINTPROCESSOR
;
416 // Call its EnumPrintProcessorDatatypesW function.
417 if (pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(pName
, pPrintProcessorName
, Level
, pDatatypes
, cbBuf
, pcbNeeded
, pcReturned
))
418 dwErrorCode
= ERROR_SUCCESS
;
420 dwErrorCode
= GetLastError();
423 SetLastError(dwErrorCode
);
424 return (dwErrorCode
== ERROR_SUCCESS
);
428 * @name LocalEnumPrintProcessors
430 * Obtains an array of all available Print Processors on this computer.
431 * Print Provider function for EnumPrintProcessorsA/EnumPrintProcessorsW.
434 * Server Name. Ignored here, because every caller of LocalEnumPrintProcessors is interested in the local directory.
436 * @param pEnvironment
437 * One of the predefined operating system and architecture "environment" strings (like "Windows NT x86").
438 * Alternatively, NULL to output the Print Processor directory of the current environment.
441 * The level of the structure supplied through pPrintProcessorInfo. This must be 1.
443 * @param pPrintProcessorInfo
444 * Pointer to the buffer that receives an array of PRINTPROCESSOR_INFO_1W structures.
445 * Can be NULL if you just want to know the required size of the buffer.
448 * Size of the buffer you supplied for pPrintProcessorInfo, in bytes.
451 * Pointer to a variable that receives the required size of the buffer for pPrintProcessorInfo, in bytes.
452 * This parameter mustn't be NULL!
455 * Pointer to a variable that receives the number of elements of the PRINTPROCESSOR_INFO_1W array.
456 * This parameter mustn't be NULL!
459 * TRUE if we successfully copied the array into pPrintProcessorInfo, FALSE otherwise.
460 * A more specific error code can be obtained through GetLastError.
463 LocalEnumPrintProcessors(LPWSTR pName
, LPWSTR pEnvironment
, DWORD Level
, LPBYTE pPrintProcessorInfo
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
)
466 DWORD cchPrintProcessor
;
468 DWORD dwPrintProcessorCount
;
472 PBYTE pCurrentOutputPrintProcessor
;
473 PBYTE pCurrentOutputPrintProcessorInfo
;
474 PRINTPROCESSOR_INFO_1W PrintProcessorInfo1
;
475 PWSTR pwszTemp
= NULL
;
480 dwErrorCode
= ERROR_INVALID_LEVEL
;
484 if (!pcbNeeded
|| !pcReturned
)
486 // This error is also caught by RPC and returned as RPC_X_NULL_REF_POINTER.
487 dwErrorCode
= ERROR_INVALID_PARAMETER
;
491 // Verify pEnvironment and open its registry key.
492 // We use the registry and not the PrintProcessorList here, because the caller may request information about a different environment.
493 dwErrorCode
= _OpenEnvironment(pEnvironment
, &hKey
);
494 if (dwErrorCode
!= ERROR_SUCCESS
)
497 // Open the "Print Processors" subkey.
498 dwErrorCode
= (DWORD
)RegOpenKeyExW(hKey
, L
"Print Processors", 0, KEY_READ
, &hSubKey
);
499 if (dwErrorCode
!= ERROR_SUCCESS
)
501 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
505 // Get the number of Print Processors and maximum sub key length.
506 dwErrorCode
= (DWORD
)RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwPrintProcessorCount
, &cchMaxSubKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
507 if (dwErrorCode
!= ERROR_SUCCESS
)
509 ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode
);
513 // Allocate a temporary buffer to let RegEnumKeyExW succeed.
514 pwszTemp
= DllAllocSplMem((cchMaxSubKey
+ 1) * sizeof(WCHAR
));
517 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
518 ERR("DllAllocSplMem failed!\n");
522 // Determine the required size of the output buffer.
525 for (i
= 0; i
< dwPrintProcessorCount
; i
++)
527 // RegEnumKeyExW sucks! Unlike similar API functions, it only returns the actual numbers of characters copied when you supply a buffer large enough.
528 // So use pwszTemp with its size cchMaxSubKey for this.
529 cchPrintProcessor
= cchMaxSubKey
+ 1;
530 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, pwszTemp
, &cchPrintProcessor
, NULL
, NULL
, NULL
, NULL
);
531 if (dwErrorCode
!= ERROR_SUCCESS
)
533 ERR("RegEnumKeyExW failed with status %lu!\n", dwErrorCode
);
537 *pcbNeeded
+= sizeof(PRINTPROCESSOR_INFO_1W
) + (cchPrintProcessor
+ 1) * sizeof(WCHAR
);
540 // Check if the supplied buffer is large enough.
541 if (cbBuf
< *pcbNeeded
)
543 dwErrorCode
= ERROR_INSUFFICIENT_BUFFER
;
547 // Put the Print Processor strings right after the last PRINTPROCESSOR_INFO_1W structure.
548 pCurrentOutputPrintProcessorInfo
= pPrintProcessorInfo
;
549 pCurrentOutputPrintProcessor
= pPrintProcessorInfo
+ dwPrintProcessorCount
* sizeof(PRINTPROCESSOR_INFO_1W
);
551 // Copy over all Print Processors.
552 for (i
= 0; i
< dwPrintProcessorCount
; i
++)
554 // This isn't really correct, but doesn't cause any harm, because we've extensively checked the size of the supplied buffer above.
555 cchPrintProcessor
= cchMaxSubKey
+ 1;
557 // Copy the Print Processor name.
558 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, (PWSTR
)pCurrentOutputPrintProcessor
, &cchPrintProcessor
, NULL
, NULL
, NULL
, NULL
);
559 if (dwErrorCode
!= ERROR_SUCCESS
)
561 ERR("RegEnumKeyExW failed with status %lu!\n", dwErrorCode
);
565 // Fill and copy the PRINTPROCESSOR_INFO_1W structure belonging to this Print Processor.
566 PrintProcessorInfo1
.pName
= (PWSTR
)pCurrentOutputPrintProcessor
;
567 CopyMemory(pCurrentOutputPrintProcessorInfo
, &PrintProcessorInfo1
, sizeof(PRINTPROCESSOR_INFO_1W
));
569 // Advance to the next PRINTPROCESSOR_INFO_1W location and string location in the output buffer.
570 pCurrentOutputPrintProcessor
+= (cchPrintProcessor
+ 1) * sizeof(WCHAR
);
571 pCurrentOutputPrintProcessorInfo
+= sizeof(PRINTPROCESSOR_INFO_1W
);
574 // We've finished successfully!
575 *pcReturned
= dwPrintProcessorCount
;
576 dwErrorCode
= ERROR_SUCCESS
;
580 DllFreeSplMem(pwszTemp
);
583 RegCloseKey(hSubKey
);
588 SetLastError(dwErrorCode
);
589 return (dwErrorCode
== ERROR_SUCCESS
);
593 * @name LocalGetPrintProcessorDirectory
595 * Obtains the path to the local Print Processor directory.
596 * Print Provider function for GetPrintProcessorDirectoryA/GetPrintProcessorDirectoryW.
599 * Server Name. Ignored here, because every caller of LocalGetPrintProcessorDirectory is interested in the local directory.
601 * @param pEnvironment
602 * One of the predefined operating system and architecture "environment" strings (like "Windows NT x86").
605 * The level of the (non-existing) structure supplied through pPrintProcessorInfo. This must be 1.
607 * @param pPrintProcessorInfo
608 * Pointer to the buffer that receives the full path to the Print Processor directory.
609 * Can be NULL if you just want to know the required size of the buffer.
612 * Size of the buffer you supplied for pPrintProcessorInfo, in bytes.
615 * Pointer to a variable that receives the required size of the buffer for pPrintProcessorInfo, in bytes.
616 * This parameter mustn't be NULL!
619 * TRUE if we successfully copied the directory into pPrintProcessorInfo, FALSE otherwise.
620 * A more specific error code can be obtained through GetLastError.
623 LocalGetPrintProcessorDirectory(PWSTR pName
, PWSTR pEnvironment
, DWORD Level
, PBYTE pPrintProcessorInfo
, DWORD cbBuf
, PDWORD pcbNeeded
)
625 const WCHAR wszPath
[] = L
"\\PRTPROCS\\";
626 const DWORD cchPath
= _countof(wszPath
) - 1;
628 DWORD cbDirectoryName
;
631 PWSTR pwszDirectory
= (PWSTR
)pPrintProcessorInfo
;
633 // Verify pEnvironment and open its registry key.
634 dwErrorCode
= _OpenEnvironment(pEnvironment
, &hKey
);
635 if (dwErrorCode
!= ERROR_SUCCESS
)
637 ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode
);
641 // Determine the size of the required buffer.
642 dwErrorCode
= (DWORD
)RegQueryValueExW(hKey
, L
"Directory", NULL
, NULL
, NULL
, &cbDirectoryName
);
643 if (dwErrorCode
!= ERROR_SUCCESS
)
645 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode
);
649 *pcbNeeded
= (cchSpoolDirectory
+ cchPath
) * sizeof(WCHAR
) + cbDirectoryName
;
651 // Is the supplied buffer large enough?
652 if (cbBuf
< *pcbNeeded
)
654 dwErrorCode
= ERROR_INSUFFICIENT_BUFFER
;
658 // Copy the path to the "prtprocs" directory into pPrintProcessorInfo
659 CopyMemory(pwszDirectory
, wszSpoolDirectory
, cchSpoolDirectory
* sizeof(WCHAR
));
660 CopyMemory(&pwszDirectory
[cchSpoolDirectory
], wszPath
, cchPath
* sizeof(WCHAR
));
662 // Get the directory name from the registry.
663 dwErrorCode
= (DWORD
)RegQueryValueExW(hKey
, L
"Directory", NULL
, NULL
, (PBYTE
)&pwszDirectory
[cchSpoolDirectory
+ cchPath
], &cbDirectoryName
);
664 if (dwErrorCode
!= ERROR_SUCCESS
)
666 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode
);
670 // We've finished successfully!
671 dwErrorCode
= ERROR_SUCCESS
;
677 SetLastError(dwErrorCode
);
678 return (dwErrorCode
== ERROR_SUCCESS
);