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 cchPrintProcessorPath
/= sizeof(WCHAR
);
144 wszPrintProcessorPath
[cchPrintProcessorPath
++] = L
'\\';
146 // Open the environment registry key.
147 dwErrorCode
= _OpenEnvironment(NULL
, &hKey
);
148 if (dwErrorCode
!= ERROR_SUCCESS
)
150 ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode
);
154 // Open the "Print Processors" subkey.
155 dwErrorCode
= (DWORD
)RegOpenKeyExW(hKey
, L
"Print Processors", 0, KEY_READ
, &hSubKey
);
156 if (dwErrorCode
!= ERROR_SUCCESS
)
158 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
162 // Get the number of Print Processors and maximum sub key length.
163 dwErrorCode
= (DWORD
)RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwSubKeys
, &cchMaxSubKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
164 if (dwErrorCode
!= ERROR_SUCCESS
)
166 ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode
);
170 // Loop through all available local Print Processors.
171 for (i
= 0; i
< dwSubKeys
; i
++)
173 // Cleanup tasks from the previous run
176 RegCloseKey(hSubSubKey
);
182 if (pPrintProcessor
->pwszName
)
183 DllFreeSplStr(pPrintProcessor
->pwszName
);
185 if (pPrintProcessor
->pDatatypesInfo1
)
186 DllFreeSplMem(pPrintProcessor
->pDatatypesInfo1
);
188 DllFreeSplMem(pPrintProcessor
);
189 pPrintProcessor
= NULL
;
192 // Create a new LOCAL_PRINT_PROCESSOR structure for it.
193 pPrintProcessor
= DllAllocSplMem(sizeof(LOCAL_PRINT_PROCESSOR
));
194 if (!pPrintProcessor
)
196 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
197 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
201 // Allocate memory for the Print Monitor Name.
202 pPrintProcessor
->pwszName
= DllAllocSplMem((cchMaxSubKey
+ 1) * sizeof(WCHAR
));
203 if (!pPrintProcessor
->pwszName
)
205 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
206 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
210 // Get the name of this Print Processor.
211 cchPrintProcessorName
= cchMaxSubKey
+ 1;
212 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, pPrintProcessor
->pwszName
, &cchPrintProcessorName
, NULL
, NULL
, NULL
, NULL
);
213 if (dwErrorCode
!= ERROR_SUCCESS
)
215 ERR("RegEnumKeyExW failed with status %ld!\n", dwErrorCode
);
219 // Open this Print Processor's registry key.
220 dwErrorCode
= (DWORD
)RegOpenKeyExW(hSubKey
, pPrintProcessor
->pwszName
, 0, KEY_READ
, &hSubSubKey
);
221 if (dwErrorCode
!= ERROR_SUCCESS
)
223 ERR("RegOpenKeyExW failed for Print Processor \"%S\" with status %lu!\n", pPrintProcessor
->pwszName
, dwErrorCode
);
227 // Get the file name of the Print Processor.
228 cbFileName
= sizeof(wszFileName
);
229 dwErrorCode
= (DWORD
)RegQueryValueExW(hSubSubKey
, L
"Driver", NULL
, NULL
, (PBYTE
)wszFileName
, &cbFileName
);
230 if (dwErrorCode
!= ERROR_SUCCESS
)
232 ERR("RegQueryValueExW failed for Print Processor \"%S\" with status %lu!\n", pPrintProcessor
->pwszName
, dwErrorCode
);
236 // Verify that our buffer is large enough.
237 if (cchPrintProcessorPath
+ cbFileName
/ sizeof(WCHAR
) > MAX_PATH
)
239 ERR("Print Processor directory \"%S\" for Print Processor \"%S\" is too long!\n", wszFileName
, pPrintProcessor
->pwszName
);
243 // Construct the full path to the Print Processor.
244 CopyMemory(&wszPrintProcessorPath
[cchPrintProcessorPath
], wszFileName
, cbFileName
);
247 hinstPrintProcessor
= LoadLibraryW(wszPrintProcessorPath
);
248 if (!hinstPrintProcessor
)
250 ERR("LoadLibraryW failed for \"%S\" with error %lu!\n", wszPrintProcessorPath
, GetLastError());
254 // Get and verify all its function pointers.
255 pPrintProcessor
->pfnClosePrintProcessor
= (PClosePrintProcessor
)GetProcAddress(hinstPrintProcessor
, "ClosePrintProcessor");
256 if (!pPrintProcessor
->pfnClosePrintProcessor
)
258 ERR("Print Processor \"%S\" exports no ClosePrintProcessor!\n", wszPrintProcessorPath
);
262 pPrintProcessor
->pfnControlPrintProcessor
= (PControlPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "ControlPrintProcessor");
263 if (!pPrintProcessor
->pfnControlPrintProcessor
)
265 ERR("Print Processor \"%S\" exports no ControlPrintProcessor!\n", wszPrintProcessorPath
);
269 pPrintProcessor
->pfnEnumPrintProcessorDatatypesW
= (PEnumPrintProcessorDatatypesW
)GetProcAddress(hinstPrintProcessor
, "EnumPrintProcessorDatatypesW");
270 if (!pPrintProcessor
->pfnEnumPrintProcessorDatatypesW
)
272 ERR("Print Processor \"%S\" exports no EnumPrintProcessorDatatypesW!\n", wszPrintProcessorPath
);
276 pPrintProcessor
->pfnGetPrintProcessorCapabilities
= (PGetPrintProcessorCapabilities
)GetProcAddress(hinstPrintProcessor
, "GetPrintProcessorCapabilities");
277 if (!pPrintProcessor
->pfnGetPrintProcessorCapabilities
)
279 ERR("Print Processor \"%S\" exports no GetPrintProcessorCapabilities!\n", wszPrintProcessorPath
);
283 pPrintProcessor
->pfnOpenPrintProcessor
= (POpenPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "OpenPrintProcessor");
284 if (!pPrintProcessor
->pfnOpenPrintProcessor
)
286 ERR("Print Processor \"%S\" exports no OpenPrintProcessor!\n", wszPrintProcessorPath
);
290 pPrintProcessor
->pfnPrintDocumentOnPrintProcessor
= (PPrintDocumentOnPrintProcessor
)GetProcAddress(hinstPrintProcessor
, "PrintDocumentOnPrintProcessor");
291 if (!pPrintProcessor
->pfnPrintDocumentOnPrintProcessor
)
293 ERR("Print Processor \"%S\" exports no PrintDocumentOnPrintProcessor!\n", wszPrintProcessorPath
);
297 // Get all supported datatypes.
298 pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(NULL
, NULL
, 1, NULL
, 0, &cbDatatypes
, &pPrintProcessor
->dwDatatypeCount
);
299 pPrintProcessor
->pDatatypesInfo1
= DllAllocSplMem(cbDatatypes
);
300 if (!pPrintProcessor
->pDatatypesInfo1
)
302 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
303 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
307 if (!pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(NULL
, NULL
, 1, (PBYTE
)pPrintProcessor
->pDatatypesInfo1
, cbDatatypes
, &cbDatatypes
, &pPrintProcessor
->dwDatatypeCount
))
309 ERR("EnumPrintProcessorDatatypesW failed for Print Processor \"%S\" with error %lu!\n", wszPrintProcessorPath
, GetLastError());
313 // Add the Print Processor to the list.
314 InsertTailList(&_PrintProcessorList
, &pPrintProcessor
->Entry
);
316 // Don't let the cleanup routines free this.
317 pPrintProcessor
= NULL
;
320 dwErrorCode
= ERROR_SUCCESS
;
325 RegCloseKey(hSubSubKey
);
329 if (pPrintProcessor
->pwszName
)
330 DllFreeSplStr(pPrintProcessor
->pwszName
);
332 if (pPrintProcessor
->pDatatypesInfo1
)
333 DllFreeSplMem(pPrintProcessor
->pDatatypesInfo1
);
335 DllFreeSplMem(pPrintProcessor
);
340 RegCloseKey(hSubKey
);
345 SetLastError(dwErrorCode
);
346 return (dwErrorCode
== ERROR_SUCCESS
);
350 * @name LocalEnumPrintProcessorDatatypes
352 * Obtains an array of all datatypes supported by a particular Print Processor.
353 * Print Provider function for EnumPrintProcessorDatatypesA/EnumPrintProcessorDatatypesW.
356 * Server Name. Ignored here, because every caller of LocalEnumPrintProcessorDatatypes is interested in the local directory.
358 * @param pPrintProcessorName
359 * The (case-insensitive) name of the Print Processor to query.
362 * The level of the structure supplied through pDatatypes. This must be 1.
365 * Pointer to the buffer that receives an array of DATATYPES_INFO_1W structures.
366 * Can be NULL if you just want to know the required size of the buffer.
369 * Size of the buffer you supplied for pDatatypes, in bytes.
372 * Pointer to a variable that receives the required size of the buffer for pDatatypes, in bytes.
373 * This parameter mustn't be NULL!
376 * Pointer to a variable that receives the number of elements of the DATATYPES_INFO_1W array.
377 * This parameter mustn't be NULL!
380 * TRUE if we successfully copied the array into pDatatypes, FALSE otherwise.
381 * A more specific error code can be obtained through GetLastError.
384 LocalEnumPrintProcessorDatatypes(LPWSTR pName
, LPWSTR pPrintProcessorName
, DWORD Level
, LPBYTE pDatatypes
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
)
387 PLOCAL_PRINT_PROCESSOR pPrintProcessor
;
392 dwErrorCode
= ERROR_INVALID_LEVEL
;
396 // Try to find the Print Processor.
397 pPrintProcessor
= FindPrintProcessor(pPrintProcessorName
);
398 if (!pPrintProcessor
)
400 dwErrorCode
= ERROR_UNKNOWN_PRINTPROCESSOR
;
404 // Call its EnumPrintProcessorDatatypesW function.
405 if (pPrintProcessor
->pfnEnumPrintProcessorDatatypesW(pName
, pPrintProcessorName
, Level
, pDatatypes
, cbBuf
, pcbNeeded
, pcReturned
))
406 dwErrorCode
= ERROR_SUCCESS
;
408 dwErrorCode
= GetLastError();
411 SetLastError(dwErrorCode
);
412 return (dwErrorCode
== ERROR_SUCCESS
);
416 * @name LocalEnumPrintProcessors
418 * Obtains an array of all available Print Processors on this computer.
419 * Print Provider function for EnumPrintProcessorsA/EnumPrintProcessorsW.
422 * Server Name. Ignored here, because every caller of LocalEnumPrintProcessors is interested in the local directory.
424 * @param pEnvironment
425 * One of the predefined operating system and architecture "environment" strings (like "Windows NT x86").
426 * Alternatively, NULL to output the Print Processor directory of the current environment.
429 * The level of the structure supplied through pPrintProcessorInfo. This must be 1.
431 * @param pPrintProcessorInfo
432 * Pointer to the buffer that receives an array of PRINTPROCESSOR_INFO_1W structures.
433 * Can be NULL if you just want to know the required size of the buffer.
436 * Size of the buffer you supplied for pPrintProcessorInfo, in bytes.
439 * Pointer to a variable that receives the required size of the buffer for pPrintProcessorInfo, in bytes.
440 * This parameter mustn't be NULL!
443 * Pointer to a variable that receives the number of elements of the PRINTPROCESSOR_INFO_1W array.
444 * This parameter mustn't be NULL!
447 * TRUE if we successfully copied the array into pPrintProcessorInfo, FALSE otherwise.
448 * A more specific error code can be obtained through GetLastError.
451 LocalEnumPrintProcessors(LPWSTR pName
, LPWSTR pEnvironment
, DWORD Level
, LPBYTE pPrintProcessorInfo
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
)
454 DWORD cchPrintProcessor
;
456 DWORD dwPrintProcessorCount
;
460 PBYTE pCurrentOutputPrintProcessor
;
461 PBYTE pCurrentOutputPrintProcessorInfo
;
462 PRINTPROCESSOR_INFO_1W PrintProcessorInfo1
;
463 PWSTR pwszTemp
= NULL
;
468 dwErrorCode
= ERROR_INVALID_LEVEL
;
472 if (!pcbNeeded
|| !pcReturned
)
474 // This error is also caught by RPC and returned as RPC_X_NULL_REF_POINTER.
475 dwErrorCode
= ERROR_INVALID_PARAMETER
;
479 // Verify pEnvironment and open its registry key.
480 // We use the registry and not the PrintProcessorList here, because the caller may request information about a different environment.
481 dwErrorCode
= _OpenEnvironment(pEnvironment
, &hKey
);
482 if (dwErrorCode
!= ERROR_SUCCESS
)
484 ERR("_OpenEnvironment failed with error %lu!\n", dwErrorCode
);
488 // Open the "Print Processors" subkey.
489 dwErrorCode
= (DWORD
)RegOpenKeyExW(hKey
, L
"Print Processors", 0, KEY_READ
, &hSubKey
);
490 if (dwErrorCode
!= ERROR_SUCCESS
)
492 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode
);
496 // Get the number of Print Processors and maximum sub key length.
497 dwErrorCode
= (DWORD
)RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwPrintProcessorCount
, &cchMaxSubKey
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
498 if (dwErrorCode
!= ERROR_SUCCESS
)
500 ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode
);
504 // Allocate a temporary buffer to let RegEnumKeyExW succeed.
505 pwszTemp
= DllAllocSplMem((cchMaxSubKey
+ 1) * sizeof(WCHAR
));
508 dwErrorCode
= ERROR_NOT_ENOUGH_MEMORY
;
509 ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
513 // Determine the required size of the output buffer.
516 for (i
= 0; i
< dwPrintProcessorCount
; i
++)
518 // RegEnumKeyExW sucks! Unlike similar API functions, it only returns the actual numbers of characters copied when you supply a buffer large enough.
519 // So use pwszTemp with its size cchMaxSubKey for this.
520 cchPrintProcessor
= cchMaxSubKey
+ 1;
521 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, pwszTemp
, &cchPrintProcessor
, NULL
, NULL
, NULL
, NULL
);
522 if (dwErrorCode
!= ERROR_SUCCESS
)
524 ERR("RegEnumKeyExW failed with status %lu!\n", dwErrorCode
);
528 *pcbNeeded
+= sizeof(PRINTPROCESSOR_INFO_1W
) + (cchPrintProcessor
+ 1) * sizeof(WCHAR
);
531 // Check if the supplied buffer is large enough.
532 if (cbBuf
< *pcbNeeded
)
534 dwErrorCode
= ERROR_INSUFFICIENT_BUFFER
;
538 // Put the Print Processor strings right after the last PRINTPROCESSOR_INFO_1W structure.
539 pCurrentOutputPrintProcessorInfo
= pPrintProcessorInfo
;
540 pCurrentOutputPrintProcessor
= pPrintProcessorInfo
+ dwPrintProcessorCount
* sizeof(PRINTPROCESSOR_INFO_1W
);
542 // Copy over all Print Processors.
543 for (i
= 0; i
< dwPrintProcessorCount
; i
++)
545 // This isn't really correct, but doesn't cause any harm, because we've extensively checked the size of the supplied buffer above.
546 cchPrintProcessor
= cchMaxSubKey
+ 1;
548 // Copy the Print Processor name.
549 dwErrorCode
= (DWORD
)RegEnumKeyExW(hSubKey
, i
, (PWSTR
)pCurrentOutputPrintProcessor
, &cchPrintProcessor
, NULL
, NULL
, NULL
, NULL
);
550 if (dwErrorCode
!= ERROR_SUCCESS
)
552 ERR("RegEnumKeyExW failed with status %lu!\n", dwErrorCode
);
556 // Fill and copy the PRINTPROCESSOR_INFO_1W structure belonging to this Print Processor.
557 PrintProcessorInfo1
.pName
= (PWSTR
)pCurrentOutputPrintProcessor
;
558 CopyMemory(pCurrentOutputPrintProcessorInfo
, &PrintProcessorInfo1
, sizeof(PRINTPROCESSOR_INFO_1W
));
560 // Advance to the next PRINTPROCESSOR_INFO_1W location and string location in the output buffer.
561 pCurrentOutputPrintProcessor
+= (cchPrintProcessor
+ 1) * sizeof(WCHAR
);
562 pCurrentOutputPrintProcessorInfo
+= sizeof(PRINTPROCESSOR_INFO_1W
);
565 // We've finished successfully!
566 *pcReturned
= dwPrintProcessorCount
;
567 dwErrorCode
= ERROR_SUCCESS
;
571 DllFreeSplMem(pwszTemp
);
574 RegCloseKey(hSubKey
);
579 SetLastError(dwErrorCode
);
580 return (dwErrorCode
== ERROR_SUCCESS
);
584 * @name LocalGetPrintProcessorDirectory
586 * Obtains the path to the local Print Processor directory.
587 * Print Provider function for GetPrintProcessorDirectoryA/GetPrintProcessorDirectoryW.
590 * Server Name. Ignored here, because every caller of LocalGetPrintProcessorDirectory is interested in the local directory.
592 * @param pEnvironment
593 * One of the predefined operating system and architecture "environment" strings (like "Windows NT x86").
594 * Alternatively, NULL to output the Print Processor directory of the current environment.
597 * The level of the (non-existing) structure supplied through pPrintProcessorInfo. This must be 1.
599 * @param pPrintProcessorInfo
600 * Pointer to the buffer that receives the full path to the Print Processor directory.
601 * Can be NULL if you just want to know the required size of the buffer.
604 * Size of the buffer you supplied for pPrintProcessorInfo, in bytes.
607 * Pointer to a variable that receives the required size of the buffer for pPrintProcessorInfo, in bytes.
608 * This parameter mustn't be NULL!
611 * TRUE if we successfully copied the directory into pPrintProcessorInfo, FALSE otherwise.
612 * A more specific error code can be obtained through GetLastError.
615 LocalGetPrintProcessorDirectory(LPWSTR pName
, LPWSTR pEnvironment
, DWORD Level
, LPBYTE pPrintProcessorInfo
, DWORD cbBuf
, LPDWORD pcbNeeded
)
617 const WCHAR wszPath
[] = L
"\\PRTPROCS\\";
618 const DWORD cchPath
= _countof(wszPath
) - 1;
627 dwErrorCode
= ERROR_INVALID_LEVEL
;
633 // This error is also caught by RPC and returned as RPC_X_NULL_REF_POINTER.
634 dwErrorCode
= ERROR_INVALID_PARAMETER
;
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
, pcbNeeded
);
648 if (dwErrorCode
!= ERROR_SUCCESS
)
650 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode
);
654 *pcbNeeded
+= cchSpoolDirectory
;
655 *pcbNeeded
+= cchPath
;
657 // Is the supplied buffer large enough?
658 if (cbBuf
< *pcbNeeded
)
660 dwErrorCode
= ERROR_INSUFFICIENT_BUFFER
;
664 // Copy the path to the "prtprocs" directory into pPrintProcessorInfo
665 CopyMemory(pPrintProcessorInfo
, wszSpoolDirectory
, cchSpoolDirectory
* sizeof(WCHAR
));
666 CopyMemory(&pPrintProcessorInfo
[cchSpoolDirectory
], wszPath
, cchPath
* sizeof(WCHAR
));
668 // Get the directory name from the registry.
669 dwErrorCode
= (DWORD
)RegQueryValueExW(hKey
, L
"Directory", NULL
, NULL
, &pPrintProcessorInfo
[cchSpoolDirectory
+ cchPath
], &cbDataWritten
);
670 if (dwErrorCode
!= ERROR_SUCCESS
)
672 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode
);
676 // We've finished successfully!
677 dwErrorCode
= ERROR_SUCCESS
;
683 SetLastError(dwErrorCode
);
684 return (dwErrorCode
== ERROR_SUCCESS
);