4 * Copyright 1996 John Harvey
5 * Copyright 1998 Andreas Mohr
6 * Copyright 1999 Klaas van Gend
16 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(winspool)
21 CRITICAL_SECTION PRINT32_RegistryBlocker;
23 #define NUM_PRINTER_MAX 10
25 typedef struct _OPENEDPRINTERA
29 LPPRINTER_DEFAULTSA lpDefault;
30 } OPENEDPRINTERA, *LPOPENEDPRINTERA;
33 /* Initialize the structure OpenedPrinter Table */
34 static OPENEDPRINTERA OpenedPrinterTableA[NUM_PRINTER_MAX] =
48 static char Printers[] =
49 "System\\CurrentControlSet\\control\\Print\\Printers\\";
50 static char Drivers[] =
51 "System\\CurrentControlSet\\control\\Print\\Environments\\Wine\\Drivers\\";
54 /******************************************************************
55 * WINSPOOL_GetOpenedPrinterEntryA
56 * Get the first place empty in the opened printer table
58 static LPOPENEDPRINTERA WINSPOOL_GetOpenedPrinterEntryA()
61 for( i=0; i< NUM_PRINTER_MAX; i++)
62 if (OpenedPrinterTableA[i].hPrinter == -1)
64 OpenedPrinterTableA[i].hPrinter = i + 1;
65 return &OpenedPrinterTableA[i];
70 /******************************************************************
71 * WINSPOOL_GetOpenedPrinterA
72 * Get the pointer to the opened printer referred by the handle
74 static LPOPENEDPRINTERA WINSPOOL_GetOpenedPrinterA(int printerHandle)
76 if((printerHandle <=0) || (printerHandle > (NUM_PRINTER_MAX + 1)))
78 return &OpenedPrinterTableA[printerHandle -1];
81 /******************************************************************
82 * DeviceCapabilities32A [WINSPOOL.151]
85 INT WINAPI DeviceCapabilitiesA(LPCSTR pDeivce,LPCSTR pPort, WORD cap,
86 LPSTR pOutput, LPDEVMODEA lpdm)
88 return GDI_CallDeviceCapabilities16(pDeivce, pPort, cap, pOutput, lpdm);
93 /*****************************************************************************
94 * DeviceCapabilities32W
96 INT WINAPI DeviceCapabilitiesW(LPCWSTR pDevice, LPCWSTR pPort,
97 WORD fwCapability, LPWSTR pOutput,
98 const DEVMODEW *pDevMode)
100 FIXME("(%p,%p,%d,%p,%p): stub\n",
101 pDevice, pPort, fwCapability, pOutput, pDevMode);
105 /******************************************************************
106 * DocumentProperties32A [WINSPOOL.155]
109 LONG WINAPI DocumentPropertiesA(HWND hWnd,HANDLE hPrinter,
110 LPSTR pDeviceName, LPDEVMODEA pDevModeOutput,
111 LPDEVMODEA pDevModeInput,DWORD fMode )
113 LPOPENEDPRINTERA lpOpenedPrinter;
114 LPSTR lpName = pDeviceName;
116 TRACE("(%d,%d,%s,%p,%p,%ld)\n",
117 hWnd,hPrinter,pDeviceName,pDevModeOutput,pDevModeInput,fMode
121 lpOpenedPrinter = WINSPOOL_GetOpenedPrinterA(hPrinter);
122 if(!lpOpenedPrinter) {
123 SetLastError(ERROR_INVALID_HANDLE);
126 lpName = lpOpenedPrinter->lpsPrinterName;
129 return GDI_CallExtDeviceMode16(hWnd, pDevModeOutput, lpName, NULL,
130 pDevModeInput, NULL, fMode);
135 /*****************************************************************************
136 * DocumentProperties32W
138 LONG WINAPI DocumentPropertiesW(HWND hWnd, HANDLE hPrinter,
140 LPDEVMODEW pDevModeOutput,
141 LPDEVMODEW pDevModeInput, DWORD fMode)
143 FIXME("(%d,%d,%s,%p,%p,%ld): stub\n",
144 hWnd,hPrinter,debugstr_w(pDeviceName),pDevModeOutput,pDevModeInput,
150 /******************************************************************
151 * OpenPrinter32A [WINSPOOL.196]
154 BOOL WINAPI OpenPrinterA(LPSTR lpPrinterName,HANDLE *phPrinter,
155 LPPRINTER_DEFAULTSA pDefault)
157 /* Not implemented: use the DesiredAccess of pDefault to set
158 the access rights to the printer */
160 LPOPENEDPRINTERA lpOpenedPrinter;
162 TRACE("(printerName: %s, pDefault %p\n", lpPrinterName, pDefault);
164 /* Get a place in the opened printer buffer*/
165 lpOpenedPrinter = WINSPOOL_GetOpenedPrinterEntryA();
167 if((lpOpenedPrinter != NULL) && (lpPrinterName !=NULL) &&
170 /* Get the name of the printer */
171 lpOpenedPrinter->lpsPrinterName =
172 HeapAlloc(GetProcessHeap(), 0, lstrlenA(lpPrinterName));
173 lstrcpyA(lpOpenedPrinter->lpsPrinterName, lpPrinterName);
175 /* Get the unique handle of the printer*/
176 *phPrinter = lpOpenedPrinter->hPrinter;
178 if (pDefault != NULL)
180 /* Allocate enough memory for the lpDefault structure */
181 lpOpenedPrinter->lpDefault =
182 HeapAlloc(GetProcessHeap(), 0, sizeof(PRINTER_DEFAULTSA));
183 lpOpenedPrinter->lpDefault->pDevMode =
184 HeapAlloc(GetProcessHeap(), 0, sizeof(DEVMODEA));
185 lpOpenedPrinter->lpDefault->pDatatype =
186 HeapAlloc(GetProcessHeap(), 0, lstrlenA(pDefault->pDatatype));
188 /*Copy the information from incoming parameter*/
189 memcpy(lpOpenedPrinter->lpDefault->pDevMode, pDefault->pDevMode,
191 lstrcpyA(lpOpenedPrinter->lpDefault->pDatatype,
192 pDefault->pDatatype);
193 lpOpenedPrinter->lpDefault->DesiredAccess =
194 pDefault->DesiredAccess;
200 if(lpOpenedPrinter == NULL)
201 FIXME("Reach the OpenedPrinterTable maximum, augment this max.\n");
205 /******************************************************************
206 * OpenPrinter32W [WINSPOOL.197]
209 BOOL WINAPI OpenPrinterW(LPWSTR lpPrinterName,HANDLE *phPrinter,
210 LPPRINTER_DEFAULTSW pDefault)
212 FIXME("(%s,%p,%p):stub\n",debugstr_w(lpPrinterName), phPrinter,
214 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
221 /******************************************************************
222 * ENUMPRINTERS_GetDWORDFromRegistryA internal
224 * Reads a DWORD from registry KeyName
227 * value on OK or NULL on error
229 DWORD ENUMPRINTERS_GetDWORDFromRegistryA(
230 HKEY hPrinterSettings, /* handle to registry key */
231 LPSTR KeyName /* name key to retrieve string from*/
238 if (RegQueryValueExA(hPrinterSettings, KeyName, NULL, &DataType,
239 Data, &DataSize)!=ERROR_SUCCESS)
240 FIXME("Query of register didn't succeed?\n");
241 if (DataType == REG_DWORD_LITTLE_ENDIAN)
242 Result = Data[0] + (Data[1]<<8) + (Data[2]<<16) + (Data[3]<<24);
243 if (DataType == REG_DWORD_BIG_ENDIAN)
244 Result = Data[3] + (Data[2]<<8) + (Data[1]<<16) + (Data[0]<<24);
249 /******************************************************************
250 * ENUMPRINTERS_AddStringFromRegistryA internal
252 * Reads a string from registry KeyName and writes it at
253 * lpbPrinters[dwNextStringPos]. Store reference to string in Dest.
256 * FALSE if there is still space left in the buffer.
258 BOOL ENUMPRINTERS_AddStringFromRegistryA(
259 HKEY hPrinterSettings, /* handle to registry key */
260 LPSTR KeyName, /* name key to retrieve string from*/
261 LPSTR* Dest, /* pointer to write string addres to */
262 LPBYTE lpbPrinters, /* buffer which receives info*/
263 LPDWORD dwNextStringPos,/* pos in buffer for next string */
264 DWORD dwBufSize, /* max size of buffer in bytes */
265 BOOL bCalcSpaceOnly /* TRUE if out-of-space in buffer */
269 LPSTR Data = (LPSTR) malloc(DataSize*sizeof(char));
271 while(RegQueryValueExA(hPrinterSettings, KeyName, NULL, &DataType,
272 Data, &DataSize)==ERROR_MORE_DATA)
274 Data = (LPSTR) realloc(Data, DataSize+2);
277 if (DataType == REG_SZ)
279 if (bCalcSpaceOnly==FALSE)
280 *Dest = &lpbPrinters[*dwNextStringPos];
281 *dwNextStringPos += DataSize+1;
282 if (*dwNextStringPos > dwBufSize)
284 if (bCalcSpaceOnly==FALSE)
286 if (DataSize==0) /* DataSize = 0 means empty string, even though*/
287 *Dest[0]=0; /* the data itself needs not to be empty */
293 WARN("Expected string setting, got something else from registry");
297 return(bCalcSpaceOnly);
302 /******************************************************************
303 * ENUMPRINTERS_AddInfo2A internal
305 * Creates a PRINTER_INFO_2A structure at: lpbPrinters[dwNextStructPos]
306 * for printer PrinterNameKey.
307 * Note that there is no check whether the information really fits!
310 * FALSE if there is still space left in the buffer.
313 * This function should not only read the registry but also ask the driver
316 BOOL ENUMPRINTERS_AddInfo2A(
317 LPSTR lpszPrinterName,/* name of printer to fill struct for*/
318 LPBYTE lpbPrinters, /* buffer which receives info*/
319 DWORD dwNextStructPos, /* pos in buffer for struct */
320 LPDWORD dwNextStringPos, /* pos in buffer for next string */
321 DWORD dwBufSize, /* max size of buffer in bytes */
322 BOOL bCalcSpaceOnly /* TRUE if out-of-space in buffer */
324 HKEY hPrinterSettings;
327 LPSTR lpszPrinterSettings = (LPSTR) malloc(strlen(Printers)+
328 strlen(lpszPrinterName)+2);
329 LPPRINTER_INFO_2A lpPInfo2 = (LPPRINTER_INFO_2A) &lpbPrinters[dwNextStructPos];
331 /* open the registry to find the attributes, etc of the printer */
332 if (lpszPrinterSettings!=NULL)
334 strcpy(lpszPrinterSettings,Printers);
335 strcat(lpszPrinterSettings,lpszPrinterName);
337 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, lpszPrinterSettings, 0,
338 KEY_READ, &hPrinterSettings) != ERROR_SUCCESS)
340 WARN("The registry did not contain my printer anymore?\n");
344 if (bCalcSpaceOnly==FALSE)
345 lpPInfo2->pServerName = NULL;
346 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
347 "Name", &(lpPInfo2->pPrinterName),
348 lpbPrinters, dwNextStringPos,
349 dwBufSize, bCalcSpaceOnly);
350 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
351 "Share Name", &(lpPInfo2->pShareName),
352 lpbPrinters, dwNextStringPos,
353 dwBufSize, bCalcSpaceOnly);
354 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
355 "Port", &(lpPInfo2->pPortName),
356 lpbPrinters, dwNextStringPos,
357 dwBufSize, bCalcSpaceOnly);
358 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
359 "Printer Driver", &(lpPInfo2->pDriverName),
360 lpbPrinters, dwNextStringPos,
361 dwBufSize, bCalcSpaceOnly);
362 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
363 "Description", &(lpPInfo2->pComment),
364 lpbPrinters, dwNextStringPos,
365 dwBufSize, bCalcSpaceOnly);
366 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
367 "Location", &(lpPInfo2->pLocation),
368 lpbPrinters, dwNextStringPos,
369 dwBufSize, bCalcSpaceOnly);
371 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
372 "Separator File", &(lpPInfo2->pSepFile),
373 lpbPrinters, dwNextStringPos,
374 dwBufSize, bCalcSpaceOnly);
375 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
376 "Print Processor", &(lpPInfo2->pPrintProcessor),
377 lpbPrinters, dwNextStringPos,
378 dwBufSize, bCalcSpaceOnly);
379 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
380 "Datatype", &(lpPInfo2->pDatatype),
381 lpbPrinters, dwNextStringPos,
382 dwBufSize, bCalcSpaceOnly);
383 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
384 "Parameters", &(lpPInfo2->pParameters),
385 lpbPrinters, dwNextStringPos,
386 dwBufSize, bCalcSpaceOnly);
387 if (bCalcSpaceOnly == FALSE)
389 lpPInfo2->pSecurityDescriptor = NULL; /* EnumPrinters doesn't return this*/
391 /* FIXME: Attributes gets LOCAL as no REMOTE exists*/
392 lpPInfo2->Attributes = ENUMPRINTERS_GetDWORDFromRegistryA(hPrinterSettings,
393 "Attributes") +PRINTER_ATTRIBUTE_LOCAL;
394 lpPInfo2->Priority = ENUMPRINTERS_GetDWORDFromRegistryA(hPrinterSettings,
396 lpPInfo2->DefaultPriority = ENUMPRINTERS_GetDWORDFromRegistryA(
397 hPrinterSettings, "Default Priority");
398 lpPInfo2->StartTime = ENUMPRINTERS_GetDWORDFromRegistryA(hPrinterSettings,
400 lpPInfo2->UntilTime = ENUMPRINTERS_GetDWORDFromRegistryA(hPrinterSettings,
402 lpPInfo2->Status = ENUMPRINTERS_GetDWORDFromRegistryA(hPrinterSettings,
404 lpPInfo2->cJobs = 0; /* FIXME: according to MSDN, this does not
405 * reflect the TotalJobs Key ??? */
406 lpPInfo2->AveragePPM = 0; /* FIXME: according to MSDN, this does not
407 * reflect the TotalPages Key ??? */
409 /* and read the devModes structure... */
410 RegQueryValueExA(hPrinterSettings, "pDevMode", NULL, &DataType,
411 NULL, &DevSize); /* should return ERROR_MORE_DATA */
412 lpPInfo2->pDevMode = (LPDEVMODEA) &lpbPrinters[*dwNextStringPos];
413 *dwNextStringPos += DevSize + 1;
415 if (*dwNextStringPos > dwBufSize)
417 if (bCalcSpaceOnly==FALSE)
418 RegQueryValueExA(hPrinterSettings, "pDevMode", NULL, &DataType,
419 (LPBYTE)lpPInfo2->pDevMode, &DevSize);
422 if (lpszPrinterSettings)
423 free(lpszPrinterSettings);
425 return(bCalcSpaceOnly);
428 /******************************************************************
429 * ENUMPRINTERS_AddInfo4A internal
431 * Creates a PRINTER_INFO_4A structure at: lpbPrinters[dwNextStructPos]
432 * for printer PrinterNameKey.
433 * Note that there is no check whether the information really fits!
436 * FALSE if there is still space left in the buffer.
439 * This function should not exist in Win95 mode, but does anyway.
441 BOOL ENUMPRINTERS_AddInfo4A(
442 LPSTR lpszPrinterName,/* name of printer to fill struct for*/
443 LPBYTE lpbPrinters, /* buffer which receives info*/
444 DWORD dwNextStructPos, /* pos in buffer for struct */
445 LPDWORD dwNextStringPos, /* pos in buffer for next string */
446 DWORD dwBufSize, /* max size of buffer in bytes */
447 BOOL bCalcSpaceOnly /* TRUE if out-of-space in buffer */
449 HKEY hPrinterSettings;
450 LPSTR lpszPrinterSettings = (LPSTR) malloc(strlen(Printers)+
451 strlen(lpszPrinterName)+2);
452 LPPRINTER_INFO_4A lpPInfo4 = (LPPRINTER_INFO_4A) &lpbPrinters[dwNextStructPos];
454 /* open the registry to find the attributes of the printer */
455 if (lpszPrinterSettings!=NULL)
457 strcpy(lpszPrinterSettings,Printers);
458 strcat(lpszPrinterSettings,lpszPrinterName);
460 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, lpszPrinterSettings, 0,
461 KEY_READ, &hPrinterSettings) != ERROR_SUCCESS)
463 WARN("The registry did not contain my printer anymore?\n");
467 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
468 "Name", &(lpPInfo4->pPrinterName),
469 lpbPrinters, dwNextStringPos,
470 dwBufSize, bCalcSpaceOnly);
471 /* FIXME: Attributes gets LOCAL as no REMOTE exists*/
472 if (bCalcSpaceOnly==FALSE)
473 lpPInfo4->Attributes = ENUMPRINTERS_GetDWORDFromRegistryA(hPrinterSettings,
474 "Attributes") +PRINTER_ATTRIBUTE_LOCAL;
476 if (lpszPrinterSettings)
477 free(lpszPrinterSettings);
479 return(bCalcSpaceOnly);
482 /******************************************************************
483 * ENUMPRINTERS_AddInfo5A internal
485 * Creates a PRINTER_INFO_5A structure at: lpbPrinters[dwNextStructPos]
486 * for printer PrinterNameKey.
487 * Settings are read from the registry.
488 * Note that there is no check whether the information really fits!
490 * FALSE if there is still space left in the buffer.
492 BOOL ENUMPRINTERS_AddInfo5A(
493 LPSTR lpszPrinterName,/* name of printer to fill struct for*/
494 LPBYTE lpbPrinters, /* buffer which receives info*/
495 DWORD dwNextStructPos, /* pos in buffer for struct */
496 LPDWORD dwNextStringPos, /* pos in buffer for next string */
497 DWORD dwBufSize, /* max size of buffer in bytes */
498 BOOL bCalcSpaceOnly /* TRUE if out-of-space in buffer */
500 HKEY hPrinterSettings;
501 LPSTR lpszPrinterSettings = (LPSTR) malloc(strlen(Printers)+
502 strlen(lpszPrinterName)+2);
503 LPPRINTER_INFO_5A lpPInfo5 = (LPPRINTER_INFO_5A) &lpbPrinters[dwNextStructPos];
505 /* open the registry to find the attributes, etc of the printer */
506 if (lpszPrinterSettings!=NULL)
508 strcpy(lpszPrinterSettings,Printers);
509 strcat(lpszPrinterSettings,lpszPrinterName);
511 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, lpszPrinterSettings, 0,
512 KEY_READ, &hPrinterSettings) != ERROR_SUCCESS)
514 WARN("The registry did not contain my printer anymore?\n");
518 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
519 "Name", &(lpPInfo5->pPrinterName),
520 lpbPrinters, dwNextStringPos,
521 dwBufSize, bCalcSpaceOnly);
522 bCalcSpaceOnly = ENUMPRINTERS_AddStringFromRegistryA(hPrinterSettings,
523 "Port", &(lpPInfo5->pPortName), lpbPrinters,
524 dwNextStringPos, dwBufSize, bCalcSpaceOnly);
525 /* FIXME: Attributes gets LOCAL as no REMOTE exists*/
526 if (bCalcSpaceOnly == FALSE)
528 lpPInfo5->Attributes = ENUMPRINTERS_GetDWORDFromRegistryA(hPrinterSettings,
529 "Attributes") +PRINTER_ATTRIBUTE_LOCAL;
530 lpPInfo5->DeviceNotSelectedTimeOut
531 = ENUMPRINTERS_GetDWORDFromRegistryA(hPrinterSettings,
533 lpPInfo5->TransmissionRetryTimeout
534 = ENUMPRINTERS_GetDWORDFromRegistryA(hPrinterSettings,
539 if (lpszPrinterSettings)
540 free(lpszPrinterSettings);
542 return(bCalcSpaceOnly);
546 /******************************************************************
547 * EnumPrintersA [WINSPOOL.174]
549 * Enumerates the available printers, print servers and print
550 * providers, depending on the specified flags, name and level.
554 * If level is set to 1:
555 * Not implemented yet!
556 * Returns TRUE with an empty list.
558 * If level is set to 2:
559 * Possible flags: PRINTER_ENUM_CONNECTIONS, PRINTER_ENUM_LOCAL.
560 * Returns an array of PRINTER_INFO_2 data structures in the
561 * lpbPrinters buffer. Note that according to MSDN also an
562 * OpenPrinter should be performed on every remote printer.
564 * If level is set to 4 (officially WinNT only):
565 * Possible flags: PRINTER_ENUM_CONNECTIONS, PRINTER_ENUM_LOCAL.
566 * Fast: Only the registry is queried to retrieve printer names,
567 * no connection to the driver is made.
568 * Returns an array of PRINTER_INFO_4 data structures in the
569 * lpbPrinters buffer.
571 * If level is set to 5 (officially WinNT4/Win9x only):
572 * Fast: Only the registry is queried to retrieve printer names,
573 * no connection to the driver is made.
574 * Returns an array of PRINTER_INFO_5 data structures in the
575 * lpbPrinters buffer.
577 * If level set to 3 or 6+:
578 * returns zero (faillure!)
580 * Returns nonzero (TRUE) on succes, or zero on faillure, use GetLastError
584 * - Only PRINTER_ENUM_LOCAL and PRINTER_ENUM_NAME are implemented.
585 * - Only levels 2, 4 and 5 are implemented at the moment.
586 * - 16-bit printer drivers are not enumerated.
587 * - Returned amount of bytes used/needed does not match the real Windoze
588 * implementation (as in this implementation, all strings are part
589 * of the buffer, whereas Win32 keeps them somewhere else)
590 * - At level 2, EnumPrinters should also call OpenPrinter for remote printers.
593 * - In a regular Wine installation, no registry settings for printers
594 * exist, which makes this function return an empty list.
596 BOOL WINAPI EnumPrintersA(
597 DWORD dwType, /* Types of print objects to enumerate */
598 LPSTR lpszName, /* name of objects to enumerate */
599 DWORD dwLevel, /* type of printer info structure */
600 LPBYTE lpbPrinters,/* buffer which receives info*/ DWORD cbBuf, /* max size of buffer in bytes */
601 LPDWORD lpdwNeeded,/* pointer to var: # bytes used/needed */
602 LPDWORD lpdwReturned/* number of entries returned */
605 HKEY hPrinterListKey;
607 char PrinterName[255];
608 DWORD PrinterNameLength=255;
610 DWORD dwNextStringPos; /* position of next space for a string in the buffer*/
611 DWORD dwStructPrinterInfoSize; /* size of a Printer_Info_X structure */
612 BOOL bCalcSpaceOnly=FALSE;/* if TRUE: don't store data, just calculate space*/
616 /* test whether we're requested to really fill in. If so,
617 * zero out the data area, and initialise some returns to zero,
618 * to prevent problems
620 if (lpbPrinters==NULL || cbBuf==0)
625 for (i=0; i<cbBuf; i++)
631 /* check for valid Flags */
632 if (dwType != PRINTER_ENUM_LOCAL && dwType != PRINTER_ENUM_NAME)
634 SetLastError(ERROR_INVALID_FLAGS);
646 SetLastError(ERROR_INVALID_PARAMETER);
650 /* Enter critical section to prevent AddPrinters() et al. to
651 * modify whilst we're reading in the registry
653 InitializeCriticalSection(&PRINT32_RegistryBlocker);
654 EnterCriticalSection(&PRINT32_RegistryBlocker);
656 /* get a pointer to a list of all printer names in the registry */
657 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Printers, 0, KEY_READ,
658 &hPrinterListKey) !=ERROR_SUCCESS)
660 /* Oh no! An empty list of printers!
661 * (which is a valid configuration anyway)
663 TRACE("No entries in the Printers part of the registry\n");
666 /* count the number of entries and check if it fits in the buffer
668 while(RegEnumKeyExA(hPrinterListKey, dwIndex, PrinterName, &PrinterNameLength,
669 NULL, NULL, NULL, &FileTime)==ERROR_SUCCESS)
671 PrinterNameLength=255;
674 *lpdwReturned = dwIndex;
678 dwStructPrinterInfoSize = sizeof(PRINTER_INFO_1A);
681 dwStructPrinterInfoSize = sizeof(PRINTER_INFO_2A);
684 dwStructPrinterInfoSize = sizeof(PRINTER_INFO_4A);
687 dwStructPrinterInfoSize = sizeof(PRINTER_INFO_5A);
690 dwStructPrinterInfoSize = 0;
693 if (dwIndex*dwStructPrinterInfoSize+1 > cbBuf)
694 bCalcSpaceOnly = TRUE;
696 /* the strings which contain e.g. PrinterName, PortName, etc,
697 * are also stored in lpbPrinters, but after the regular structs.
698 * dwNextStringPos will always point to the next free place for a
701 dwNextStringPos=(dwIndex+1)*dwStructPrinterInfoSize;
703 /* check each entry: if OK, add to list in corresponding INFO .
705 for(dwIndex=0; dwIndex < *lpdwReturned; dwIndex++)
707 PrinterNameLength=255;
708 if (RegEnumKeyExA(hPrinterListKey, dwIndex, PrinterName, &PrinterNameLength,
709 NULL, NULL, NULL, &FileTime)!=ERROR_SUCCESS)
710 break; /* exit for loop*/
712 /* check whether this printer is allowed in the list
713 * by comparing name to lpszName
715 if (dwType == PRINTER_ENUM_NAME)
716 if (strcmp(PrinterName,lpszName)!=0)
722 /* FIXME: unimplemented */
725 bCalcSpaceOnly = ENUMPRINTERS_AddInfo2A(PrinterName, lpbPrinters,
726 dwIndex*dwStructPrinterInfoSize,
727 &dwNextStringPos, cbBuf, bCalcSpaceOnly);
730 bCalcSpaceOnly = ENUMPRINTERS_AddInfo4A(PrinterName, lpbPrinters,
731 dwIndex*dwStructPrinterInfoSize,
732 &dwNextStringPos, cbBuf, bCalcSpaceOnly);
735 bCalcSpaceOnly = ENUMPRINTERS_AddInfo5A(PrinterName, lpbPrinters,
736 dwIndex*dwStructPrinterInfoSize,
737 &dwNextStringPos, cbBuf, bCalcSpaceOnly);
741 RegCloseKey(hPrinterListKey);
742 *lpdwNeeded = dwNextStringPos;
744 if (bCalcSpaceOnly==TRUE)
746 if (lpbPrinters!=NULL)
749 for (i=0; i<cbBuf; i++)
754 LeaveCriticalSection(&PRINT32_RegistryBlocker);
758 /******************************************************************
759 * EnumPrinters32W [WINSPOOL.175]
762 BOOL WINAPI EnumPrintersW(DWORD dwType, LPWSTR lpszName,
763 DWORD dwLevel, LPBYTE lpbPrinters,
764 DWORD cbBuf, LPDWORD lpdwNeeded,
765 LPDWORD lpdwReturned)
767 FIXME("Nearly empty stub\n");
773 /******************************************************************
774 * AddMonitor32A [WINSPOOL.107]
777 BOOL WINAPI AddMonitorA(LPCSTR pName, DWORD Level, LPBYTE pMonitors)
779 FIXME("(%s,%lx,%p):stub!\n", pName, Level, pMonitors);
780 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
784 /******************************************************************
785 * DeletePrinterDriver32A [WINSPOOL.146]
789 DeletePrinterDriverA (LPSTR pName, LPSTR pEnvironment, LPSTR pDriverName)
791 FIXME("(%s,%s,%s):stub\n",debugstr_a(pName),debugstr_a(pEnvironment),
792 debugstr_a(pDriverName));
793 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
798 /******************************************************************
799 * DeleteMonitor32A [WINSPOOL.135]
803 DeleteMonitorA (LPSTR pName, LPSTR pEnvironment, LPSTR pMonitorName)
805 FIXME("(%s,%s,%s):stub\n",debugstr_a(pName),debugstr_a(pEnvironment),
806 debugstr_a(pMonitorName));
807 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
812 /******************************************************************
813 * DeletePort32A [WINSPOOL.137]
817 DeletePortA (LPSTR pName, HWND hWnd, LPSTR pPortName)
819 FIXME("(%s,0x%08x,%s):stub\n",debugstr_a(pName),hWnd,
820 debugstr_a(pPortName));
821 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
825 /******************************************************************************
826 * SetPrinter32W [WINSPOOL.214]
836 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
840 /******************************************************************************
841 * WritePrinter32 [WINSPOOL.223]
851 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
855 /*****************************************************************************
856 * AddForm32A [WINSPOOL.103]
858 BOOL WINAPI AddFormA(HANDLE hPrinter, DWORD Level, LPBYTE pForm)
860 FIXME("(%d,%ld,%p): stub\n", hPrinter, Level, pForm);
864 /*****************************************************************************
865 * AddForm32W [WINSPOOL.104]
867 BOOL WINAPI AddFormW(HANDLE hPrinter, DWORD Level, LPBYTE pForm)
869 FIXME("(%d,%ld,%p): stub\n", hPrinter, Level, pForm);
873 /*****************************************************************************
874 * AddJob32A [WINSPOOL.105]
876 BOOL WINAPI AddJobA(HANDLE hPrinter, DWORD Level, LPBYTE pData,
877 DWORD cbBuf, LPDWORD pcbNeeded)
879 FIXME("(%d,%ld,%p,%ld,%p): stub\n", hPrinter, Level, pData, cbBuf,
884 /*****************************************************************************
885 * AddJob32W [WINSPOOL.106]
887 BOOL WINAPI AddJobW(HANDLE hPrinter, DWORD Level, LPBYTE pData, DWORD cbBuf,
890 FIXME("(%d,%ld,%p,%ld,%p): stub\n", hPrinter, Level, pData, cbBuf,
895 /*****************************************************************************
896 * AddPrinter32A [WINSPOOL.117]
898 HANDLE WINAPI AddPrinterA(LPSTR pName, DWORD Level, LPBYTE pPrinter)
900 PRINTER_INFO_2A *pi = (PRINTER_INFO_2A *) pPrinter;
903 HKEY hkeyPrinter, hkeyPrinters, hkeyDriver, hkeyDrivers;
905 TRACE("(%s,%ld,%p)\n", pName, Level, pPrinter);
908 FIXME("pName = `%s' - unsupported\n", pName);
909 SetLastError(ERROR_INVALID_PARAMETER);
913 WARN("Level = %ld\n", Level);
914 SetLastError(ERROR_INVALID_LEVEL);
918 SetLastError(ERROR_INVALID_PARAMETER);
921 if(RegCreateKeyA(HKEY_LOCAL_MACHINE, Printers, &hkeyPrinters) !=
923 ERR("Can't create Printers key\n");
926 if(RegOpenKeyA(hkeyPrinters, pi->pPrinterName, &hkeyPrinter) ==
928 SetLastError(ERROR_PRINTER_ALREADY_EXISTS);
929 RegCloseKey(hkeyPrinter);
930 RegCloseKey(hkeyPrinters);
933 if(RegCreateKeyA(HKEY_LOCAL_MACHINE, Drivers, &hkeyDrivers) !=
935 ERR("Can't create Drivers key\n");
936 RegCloseKey(hkeyPrinters);
939 if(RegOpenKeyA(hkeyDrivers, pi->pDriverName, &hkeyDriver) !=
941 WARN("Can't find driver `%s'\n", pi->pDriverName);
942 RegCloseKey(hkeyPrinters);
943 RegCloseKey(hkeyDrivers);
944 SetLastError(ERROR_UNKNOWN_PRINTER_DRIVER);
947 RegCloseKey(hkeyDriver);
948 RegCloseKey(hkeyDrivers);
949 if(strcasecmp(pi->pPrintProcessor, "WinPrint")) { /* FIXME */
950 WARN("Can't find processor `%s'\n", pi->pPrintProcessor);
951 SetLastError(ERROR_UNKNOWN_PRINTPROCESSOR);
952 RegCloseKey(hkeyPrinters);
955 if(RegCreateKeyA(hkeyPrinters, pi->pPrinterName, &hkeyPrinter) !=
957 WARN("Can't create printer `%s'\n", pi->pPrinterName);
958 SetLastError(ERROR_INVALID_PRINTER_NAME);
959 RegCloseKey(hkeyPrinters);
962 RegSetValueExA(hkeyPrinter, "Attributes", 0, REG_DWORD,
963 (LPSTR)&pi->Attributes, sizeof(DWORD));
964 RegSetValueExA(hkeyPrinter, "Default DevMode", 0, REG_BINARY,
965 (LPSTR)&pi->pDevMode,
966 pi->pDevMode ? pi->pDevMode->dmSize : 0);
967 RegSetValueExA(hkeyPrinter, "Description", 0, REG_SZ, pi->pComment, 0);
968 RegSetValueExA(hkeyPrinter, "Location", 0, REG_SZ, pi->pLocation, 0);
969 RegSetValueExA(hkeyPrinter, "Name", 0, REG_SZ, pi->pPrinterName, 0);
970 RegSetValueExA(hkeyPrinter, "Parameters", 0, REG_SZ, pi->pParameters, 0);
971 RegSetValueExA(hkeyPrinter, "Port", 0, REG_SZ, pi->pPortName, 0);
972 RegSetValueExA(hkeyPrinter, "Print Processor", 0, REG_SZ,
973 pi->pPrintProcessor, 0);
974 RegSetValueExA(hkeyPrinter, "Printer Driver", 0, REG_SZ, pi->pDriverName,
976 RegSetValueExA(hkeyPrinter, "Priority", 0, REG_DWORD,
977 (LPSTR)&pi->Priority, sizeof(DWORD));
978 RegSetValueExA(hkeyPrinter, "Separator File", 0, REG_SZ, pi->pSepFile, 0);
979 RegSetValueExA(hkeyPrinter, "Share Name", 0, REG_SZ, pi->pShareName, 0);
980 RegSetValueExA(hkeyPrinter, "Start Time", 0, REG_DWORD,
981 (LPSTR)&pi->StartTime, sizeof(DWORD));
982 RegSetValueExA(hkeyPrinter, "Status", 0, REG_DWORD,
983 (LPSTR)&pi->Status, sizeof(DWORD));
984 RegSetValueExA(hkeyPrinter, "Until Time", 0, REG_DWORD,
985 (LPSTR)&pi->UntilTime, sizeof(DWORD));
987 RegCloseKey(hkeyPrinter);
988 RegCloseKey(hkeyPrinters);
989 if(!OpenPrinterA(pi->pPrinterName, &retval, NULL)) {
990 ERR("OpenPrinter failing\n");
996 /*****************************************************************************
997 * AddPrinter32W [WINSPOOL.122]
999 HANDLE WINAPI AddPrinterW(LPWSTR pName, DWORD Level, LPBYTE pPrinter)
1001 FIXME("(%p,%ld,%p): stub\n", pName, Level, pPrinter);
1006 /*****************************************************************************
1007 * ClosePrinter32 [WINSPOOL.126]
1009 BOOL WINAPI ClosePrinter(HANDLE hPrinter)
1011 LPOPENEDPRINTERA lpOpenedPrinter;
1013 if ((hPrinter != -1) && (hPrinter < NUM_PRINTER_MAX + 1))
1015 lpOpenedPrinter = WINSPOOL_GetOpenedPrinterA(hPrinter);
1016 HeapFree(GetProcessHeap(), 0, lpOpenedPrinter->lpsPrinterName);
1017 lpOpenedPrinter->lpsPrinterName = NULL;
1019 /* Free the memory of lpDefault if it has been initialized*/
1020 if(lpOpenedPrinter->lpDefault != NULL)
1022 HeapFree(GetProcessHeap(), 0,
1023 lpOpenedPrinter->lpDefault->pDevMode);
1024 HeapFree(GetProcessHeap(), 0,
1025 lpOpenedPrinter->lpDefault->pDatatype);
1026 HeapFree(GetProcessHeap(), 0,
1027 lpOpenedPrinter->lpDefault);
1028 lpOpenedPrinter->lpDefault = NULL;
1031 lpOpenedPrinter->hPrinter = -1;
1038 /*****************************************************************************
1039 * DeleteForm32A [WINSPOOL.133]
1041 BOOL WINAPI DeleteFormA(HANDLE hPrinter, LPSTR pFormName)
1043 FIXME("(%d,%s): stub\n", hPrinter, pFormName);
1047 /*****************************************************************************
1048 * DeleteForm32W [WINSPOOL.134]
1050 BOOL WINAPI DeleteFormW(HANDLE hPrinter, LPWSTR pFormName)
1052 FIXME("(%d,%s): stub\n", hPrinter, debugstr_w(pFormName));
1056 /*****************************************************************************
1057 * DeletePrinter32 [WINSPOOL.143]
1059 BOOL WINAPI DeletePrinter(HANDLE hPrinter)
1061 FIXME("(%d): stub\n", hPrinter);
1065 /*****************************************************************************
1066 * SetPrinter32A [WINSPOOL.211]
1068 BOOL WINAPI SetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter,
1071 FIXME("(%d,%ld,%p,%ld): stub\n",hPrinter,Level,pPrinter,Command);
1075 /*****************************************************************************
1076 * SetJob32A [WINSPOOL.209]
1078 BOOL WINAPI SetJobA(HANDLE hPrinter, DWORD JobId, DWORD Level,
1079 LPBYTE pJob, DWORD Command)
1081 FIXME("(%d,%ld,%ld,%p,%ld): stub\n",hPrinter,JobId,Level,pJob,
1086 /*****************************************************************************
1087 * SetJob32W [WINSPOOL.210]
1089 BOOL WINAPI SetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level,
1090 LPBYTE pJob, DWORD Command)
1092 FIXME("(%d,%ld,%ld,%p,%ld): stub\n",hPrinter,JobId,Level,pJob,
1097 /*****************************************************************************
1098 * GetForm32A [WINSPOOL.181]
1100 BOOL WINAPI GetFormA(HANDLE hPrinter, LPSTR pFormName, DWORD Level,
1101 LPBYTE pForm, DWORD cbBuf, LPDWORD pcbNeeded)
1103 FIXME("(%d,%s,%ld,%p,%ld,%p): stub\n",hPrinter,pFormName,
1104 Level,pForm,cbBuf,pcbNeeded);
1108 /*****************************************************************************
1109 * GetForm32W [WINSPOOL.182]
1111 BOOL WINAPI GetFormW(HANDLE hPrinter, LPWSTR pFormName, DWORD Level,
1112 LPBYTE pForm, DWORD cbBuf, LPDWORD pcbNeeded)
1114 FIXME("(%d,%s,%ld,%p,%ld,%p): stub\n",hPrinter,
1115 debugstr_w(pFormName),Level,pForm,cbBuf,pcbNeeded);
1119 /*****************************************************************************
1120 * SetForm32A [WINSPOOL.207]
1122 BOOL WINAPI SetFormA(HANDLE hPrinter, LPSTR pFormName, DWORD Level,
1125 FIXME("(%d,%s,%ld,%p): stub\n",hPrinter,pFormName,Level,pForm);
1129 /*****************************************************************************
1130 * SetForm32W [WINSPOOL.208]
1132 BOOL WINAPI SetFormW(HANDLE hPrinter, LPWSTR pFormName, DWORD Level,
1135 FIXME("(%d,%p,%ld,%p): stub\n",hPrinter,pFormName,Level,pForm);
1139 /*****************************************************************************
1140 * ReadPrinter32 [WINSPOOL.202]
1142 BOOL WINAPI ReadPrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf,
1143 LPDWORD pNoBytesRead)
1145 FIXME("(%d,%p,%ld,%p): stub\n",hPrinter,pBuf,cbBuf,pNoBytesRead);
1149 /*****************************************************************************
1150 * ResetPrinter32A [WINSPOOL.203]
1152 BOOL WINAPI ResetPrinterA(HANDLE hPrinter, LPPRINTER_DEFAULTSA pDefault)
1154 FIXME("(%d, %p): stub\n", hPrinter, pDefault);
1158 /*****************************************************************************
1159 * ResetPrinter32W [WINSPOOL.204]
1161 BOOL WINAPI ResetPrinterW(HANDLE hPrinter, LPPRINTER_DEFAULTSW pDefault)
1163 FIXME("(%d, %p): stub\n", hPrinter, pDefault);
1168 /*****************************************************************************
1169 * WINSPOOL_GetStringFromRegA
1171 * Get ValueName from hkey storing result in str. buflen is space left in str
1173 static BOOL WINSPOOL_GetStringFromRegA(HKEY hkey, LPCSTR ValueName, LPSTR ptr,
1174 DWORD buflen, DWORD *needed)
1176 DWORD sz = buflen, type;
1179 ret = RegQueryValueExA(hkey, ValueName, 0, &type, ptr, &sz);
1181 if(ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA) {
1182 ERR("Got ret = %ld\n", ret);
1190 /*****************************************************************************
1191 * GetPrinter32A [WINSPOOL.187]
1193 BOOL WINAPI GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter,
1194 DWORD cbBuf, LPDWORD pcbNeeded)
1196 OPENEDPRINTERA *lpOpenedPrinter;
1197 DWORD size, needed = 0;
1199 HKEY hkeyPrinter, hkeyPrinters;
1201 TRACE("(%d,%ld,%p,%ld,%p)\n",hPrinter,Level,pPrinter,cbBuf, pcbNeeded);
1203 lpOpenedPrinter = WINSPOOL_GetOpenedPrinterA(hPrinter);
1204 if(!lpOpenedPrinter) {
1205 SetLastError(ERROR_INVALID_HANDLE);
1208 if(RegCreateKeyA(HKEY_LOCAL_MACHINE, Printers, &hkeyPrinters) !=
1210 ERR("Can't create Printers key\n");
1213 if(RegOpenKeyA(hkeyPrinters, lpOpenedPrinter->lpsPrinterName, &hkeyPrinter)
1215 ERR("Can't find opened printer `%s' in registry\n",
1216 lpOpenedPrinter->lpsPrinterName);
1217 RegCloseKey(hkeyPrinters);
1218 SetLastError(ERROR_INVALID_PRINTER_NAME); /* ? */
1225 PRINTER_INFO_2A *pi2 = (PRINTER_INFO_2A *)pPrinter;
1227 size = sizeof(PRINTER_INFO_2A);
1229 ptr = pPrinter + size;
1231 memset(pPrinter, 0, size);
1236 WINSPOOL_GetStringFromRegA(hkeyPrinter, "Name", ptr, cbBuf, &size);
1238 pi2->pPrinterName = ptr;
1244 WINSPOOL_GetStringFromRegA(hkeyPrinter, "Port", ptr, cbBuf, &size);
1246 pi2->pPortName = ptr;
1252 WINSPOOL_GetStringFromRegA(hkeyPrinter, "Printer Driver", ptr, cbBuf,
1255 pi2->pDriverName = ptr;
1261 WINSPOOL_GetStringFromRegA(hkeyPrinter, "Default DevMode", ptr, cbBuf,
1264 pi2->pDevMode = (LPDEVMODEA)ptr;
1270 WINSPOOL_GetStringFromRegA(hkeyPrinter, "Print Processor", ptr, cbBuf,
1273 pi2->pPrintProcessor = ptr;
1284 PRINTER_INFO_5A *pi5 = (PRINTER_INFO_5A *)pPrinter;
1286 size = sizeof(PRINTER_INFO_5A);
1288 ptr = pPrinter + size;
1290 memset(pPrinter, 0, size);
1295 WINSPOOL_GetStringFromRegA(hkeyPrinter, "Name", ptr, cbBuf, &size);
1297 pi5->pPrinterName = ptr;
1303 WINSPOOL_GetStringFromRegA(hkeyPrinter, "Port", ptr, cbBuf, &size);
1305 pi5->pPortName = ptr;
1315 FIXME("Unimplemented level %ld\n", Level);
1316 SetLastError(ERROR_INVALID_LEVEL);
1317 RegCloseKey(hkeyPrinters);
1318 RegCloseKey(hkeyPrinter);
1322 RegCloseKey(hkeyPrinter);
1323 RegCloseKey(hkeyPrinters);
1325 if(pcbNeeded) *pcbNeeded = needed;
1326 if(cbBuf) return TRUE;
1327 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1332 /*****************************************************************************
1333 * GetPrinter32W [WINSPOOL.194]
1335 BOOL WINAPI GetPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter,
1336 DWORD cbBuf, LPDWORD pcbNeeded)
1338 FIXME("(%d,%ld,%p,%ld,%p): stub\n", hPrinter, Level, pPrinter,
1344 /*****************************************************************************
1345 * GetPrinterDriver32A [WINSPOOL.190]
1347 BOOL WINAPI GetPrinterDriverA(HANDLE hPrinter, LPSTR pEnvironment,
1348 DWORD Level, LPBYTE pDriverInfo,
1349 DWORD cbBuf, LPDWORD pcbNeeded)
1351 OPENEDPRINTERA *lpOpenedPrinter;
1352 char DriverName[100];
1353 DWORD ret, type, size, dw, needed = 0;
1355 HKEY hkeyPrinter, hkeyPrinters, hkeyDriver, hkeyDrivers;
1357 TRACE("(%d,%s,%ld,%p,%ld,%p)\n",hPrinter,pEnvironment,
1358 Level,pDriverInfo,cbBuf, pcbNeeded);
1360 lpOpenedPrinter = WINSPOOL_GetOpenedPrinterA(hPrinter);
1361 if(!lpOpenedPrinter) {
1362 SetLastError(ERROR_INVALID_HANDLE);
1366 FIXME("pEnvironment = `%s'\n", pEnvironment);
1367 SetLastError(ERROR_INVALID_ENVIRONMENT);
1370 if(Level < 1 || Level > 3) {
1371 SetLastError(ERROR_INVALID_LEVEL);
1374 if(RegCreateKeyA(HKEY_LOCAL_MACHINE, Printers, &hkeyPrinters) !=
1376 ERR("Can't create Printers key\n");
1379 if(RegOpenKeyA(hkeyPrinters, lpOpenedPrinter->lpsPrinterName, &hkeyPrinter)
1381 ERR("Can't find opened printer `%s' in registry\n",
1382 lpOpenedPrinter->lpsPrinterName);
1383 RegCloseKey(hkeyPrinters);
1384 SetLastError(ERROR_INVALID_PRINTER_NAME); /* ? */
1387 size = sizeof(DriverName);
1388 ret = RegQueryValueExA(hkeyPrinter, "Printer Driver", 0, &type, DriverName,
1390 RegCloseKey(hkeyPrinter);
1391 RegCloseKey(hkeyPrinters);
1392 if(ret != ERROR_SUCCESS) {
1393 ERR("Can't get DriverName for printer `%s'\n",
1394 lpOpenedPrinter->lpsPrinterName);
1397 if(RegCreateKeyA(HKEY_LOCAL_MACHINE, Drivers, &hkeyDrivers) !=
1399 ERR("Can't create Drivers key\n");
1402 if(RegOpenKeyA(hkeyDrivers, DriverName, &hkeyDriver)
1404 ERR("Can't find driver `%s' in registry\n", DriverName);
1405 RegCloseKey(hkeyDrivers);
1406 SetLastError(ERROR_UNKNOWN_PRINTER_DRIVER); /* ? */
1412 size = sizeof(DRIVER_INFO_1A);
1415 size = sizeof(DRIVER_INFO_2A);
1418 size = sizeof(DRIVER_INFO_3A);
1421 ERR("Invalid level\n");
1426 ptr = pDriverInfo + size;
1432 size = strlen(DriverName) + 1;
1435 strcpy(ptr, DriverName);
1437 ((DRIVER_INFO_1A *)pDriverInfo)->pName = ptr;
1439 ((DRIVER_INFO_2A *)pDriverInfo)->pName = ptr;
1445 DRIVER_INFO_2A *di2 = (DRIVER_INFO_2A *)pDriverInfo;
1448 if(RegQueryValueExA(hkeyDriver, "Version", 0, &type, (PBYTE)&dw,
1451 WARN("Can't get Version\n");
1455 size = strlen("Wine") + 1; /* FIXME */
1458 strcpy(ptr, "Wine");
1459 di2->pEnvironment = ptr;
1465 WINSPOOL_GetStringFromRegA(hkeyDriver, "Driver", ptr, cbBuf, &size);
1467 di2->pDriverPath = ptr;
1473 WINSPOOL_GetStringFromRegA(hkeyDriver, "Data File", ptr, cbBuf, &size);
1475 di2->pDataFile = ptr;
1481 WINSPOOL_GetStringFromRegA(hkeyDriver, "Configuration File", ptr,
1484 di2->pConfigFile = ptr;
1492 DRIVER_INFO_3A *di3 = (DRIVER_INFO_3A *)pDriverInfo;
1494 WINSPOOL_GetStringFromRegA(hkeyDriver, "Help File", ptr, cbBuf, &size);
1496 di3->pHelpFile = ptr;
1502 WINSPOOL_GetStringFromRegA(hkeyDriver, "Dependent Files", ptr, cbBuf,
1505 di3->pDependentFiles = ptr;
1511 WINSPOOL_GetStringFromRegA(hkeyDriver, "Monitor", ptr, cbBuf, &size);
1513 di3->pMonitorName = ptr;
1519 WINSPOOL_GetStringFromRegA(hkeyDriver, "DataType", ptr, cbBuf, &size);
1521 di3->pDefaultDataType = ptr;
1527 RegCloseKey(hkeyDriver);
1528 RegCloseKey(hkeyDrivers);
1530 if(pcbNeeded) *pcbNeeded = needed;
1531 if(cbBuf) return TRUE;
1532 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1536 /*****************************************************************************
1537 * GetPrinterDriver32W [WINSPOOL.193]
1539 BOOL WINAPI GetPrinterDriverW(HANDLE hPrinter, LPWSTR pEnvironment,
1540 DWORD Level, LPBYTE pDriverInfo,
1541 DWORD cbBuf, LPDWORD pcbNeeded)
1543 FIXME("(%d,%p,%ld,%p,%ld,%p): stub\n",hPrinter,pEnvironment,
1544 Level,pDriverInfo,cbBuf, pcbNeeded);
1548 /*****************************************************************************
1549 * GetPrinterDriverDirectoryA [WINSPOOL.191]
1551 BOOL WINAPI GetPrinterDriverDirectoryA(LPSTR pName, LPSTR pEnvironment,
1552 DWORD Level, LPBYTE pDriverDirectory,
1553 DWORD cbBuf, LPDWORD pcbNeeded)
1557 TRACE("(%s, %s, %ld, %p, %ld, %p)\n", pName, pEnvironment, Level,
1558 pDriverDirectory, cbBuf, pcbNeeded);
1560 FIXME("pName = `%s' - unsupported\n", pName);
1561 SetLastError(ERROR_INVALID_PARAMETER);
1564 if(pEnvironment != NULL) {
1565 FIXME("pEnvironment = `%s' - unsupported\n", pEnvironment);
1566 SetLastError(ERROR_INVALID_ENVIRONMENT);
1569 if(Level != 1) /* win95 ignores this so we just carry on */
1570 WARN("Level = %ld - assuming 1\n", Level);
1572 /* FIXME should read from registry */
1573 needed = GetSystemDirectoryA(pDriverDirectory, cbBuf);
1576 *pcbNeeded = needed;
1577 if(needed > cbBuf) {
1578 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1585 /*****************************************************************************
1586 * GetPrinterDriverDirectoryW [WINSPOOL.192]
1588 BOOL WINAPI GetPrinterDriverDirectoryW(LPWSTR pName, LPWSTR pEnvironment,
1589 DWORD Level, LPBYTE pDriverDirectory,
1590 DWORD cbBuf, LPDWORD pcbNeeded)
1592 LPSTR pNameA = NULL, pEnvironmentA = NULL;
1596 pNameA = HEAP_strdupWtoA( GetProcessHeap(), 0, pName );
1598 pEnvironmentA = HEAP_strdupWtoA( GetProcessHeap(), 0, pEnvironment );
1599 ret = GetPrinterDriverDirectoryA( pNameA, pEnvironmentA, Level,
1600 pDriverDirectory, cbBuf, pcbNeeded );
1602 HeapFree( GetProcessHeap(), 0, pNameA );
1604 HeapFree( GetProcessHeap(), 0, pEnvironment );
1609 /*****************************************************************************
1610 * AddPrinterDriver32A [WINSPOOL.120]
1612 BOOL WINAPI AddPrinterDriverA(LPSTR pName, DWORD level, LPBYTE pDriverInfo)
1615 HKEY hkeyDrivers, hkeyName;
1617 TRACE("(%s,%ld,%p)\n",pName,level,pDriverInfo);
1619 if(level != 2 && level != 3) {
1620 SetLastError(ERROR_INVALID_LEVEL);
1624 FIXME("pName= `%s' - unsupported\n", pName);
1625 SetLastError(ERROR_INVALID_PARAMETER);
1629 WARN("pDriverInfo == NULL");
1630 SetLastError(ERROR_INVALID_PARAMETER);
1635 di3 = *(DRIVER_INFO_3A *)pDriverInfo;
1637 memset(&di3, 0, sizeof(di3));
1638 *(DRIVER_INFO_2A *)&di3 = *(DRIVER_INFO_2A *)pDriverInfo;
1641 if(!di3.pName || !di3.pDriverPath || !di3.pConfigFile ||
1643 SetLastError(ERROR_INVALID_PARAMETER);
1646 if(!di3.pDefaultDataType) di3.pDefaultDataType = "";
1647 if(!di3.pDependentFiles) di3.pDependentFiles = "\0";
1648 if(!di3.pHelpFile) di3.pHelpFile = "";
1649 if(!di3.pMonitorName) di3.pMonitorName = "";
1651 if(di3.pEnvironment) {
1652 FIXME("pEnvironment = `%s'\n", di3.pEnvironment);
1653 SetLastError(ERROR_INVALID_ENVIRONMENT);
1656 if(RegCreateKeyA(HKEY_LOCAL_MACHINE, Drivers, &hkeyDrivers) !=
1658 ERR("Can't create Drivers key\n");
1662 if(level == 2) { /* apparently can't overwrite with level2 */
1663 if(RegOpenKeyA(hkeyDrivers, di3.pName, &hkeyName) == ERROR_SUCCESS) {
1664 RegCloseKey(hkeyName);
1665 RegCloseKey(hkeyDrivers);
1666 WARN("Trying to create existing printer driver `%s'\n", di3.pName);
1667 SetLastError(ERROR_PRINTER_DRIVER_ALREADY_INSTALLED);
1671 if(RegCreateKeyA(hkeyDrivers, di3.pName, &hkeyName) != ERROR_SUCCESS) {
1672 RegCloseKey(hkeyDrivers);
1673 ERR("Can't create Name key\n");
1676 RegSetValueExA(hkeyName, "Configuration File", 0, REG_SZ, di3.pConfigFile,
1678 RegSetValueExA(hkeyName, "Data File", 0, REG_SZ, di3.pDataFile, 0);
1679 RegSetValueExA(hkeyName, "Driver", 0, REG_SZ, di3.pDriverPath, 0);
1680 RegSetValueExA(hkeyName, "Version", 0, REG_DWORD, (LPSTR)&di3.cVersion,
1682 RegSetValueExA(hkeyName, "Datatype", 0, REG_SZ, di3.pDefaultDataType, 0);
1683 RegSetValueExA(hkeyName, "Dependent Files", 0, REG_MULTI_SZ,
1684 di3.pDependentFiles, 0);
1685 RegSetValueExA(hkeyName, "Help File", 0, REG_SZ, di3.pHelpFile, 0);
1686 RegSetValueExA(hkeyName, "Monitor", 0, REG_SZ, di3.pMonitorName, 0);
1687 RegCloseKey(hkeyName);
1688 RegCloseKey(hkeyDrivers);
1692 /*****************************************************************************
1693 * AddPrinterDriver32W [WINSPOOL.121]
1695 BOOL WINAPI AddPrinterDriverW(LPWSTR printerName,DWORD level,
1698 FIXME("(%s,%ld,%p): stub\n",debugstr_w(printerName),
1704 /*****************************************************************************
1705 * PrinterProperties [WINSPOOL.201]
1707 * Displays a dialog to set the properties of the printer.
1710 * nonzero on succes or zero on faillure
1713 * implemented as stub only
1715 BOOL WINAPI PrinterProperties(HWND hWnd, /* handle to parent window */
1716 HANDLE hPrinter /* handle to printer object */
1718 FIXME("(%d,%d): stub\n", hWnd, hPrinter);
1719 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);