- Added debugging.
[wine/testsucceed.git] / dlls / gdi / printdrv.c
blobacf9eb25adaa3e8d3565fbeac0a46afcca7fbe84
1 /*
2 * Implementation of some printer driver bits
3 *
4 * Copyright 1996 John Harvey
5 * Copyright 1998 Huw Davies
6 * Copyright 1998 Andreas Mohr
7 * Copyright 1999 Klaas van Gend
8 */
10 #include "config.h"
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <ctype.h>
16 #include <errno.h>
17 #include <unistd.h>
18 #include <fcntl.h>
19 #include "winbase.h"
20 #include "winuser.h"
21 #include "wine/winbase16.h"
22 #include "wine/wingdi16.h"
23 #include "winspool.h"
24 #include "winerror.h"
25 #include "winreg.h"
26 #include "debugtools.h"
27 #include "gdi.h"
28 #include "heap.h"
29 #include "file.h"
31 DEFAULT_DEBUG_CHANNEL(print);
33 static char PrinterModel[] = "Printer Model";
34 static char DefaultDevMode[] = "Default DevMode";
35 static char PrinterDriverData[] = "PrinterDriverData";
36 static char Printers[] = "System\\CurrentControlSet\\Control\\Print\\Printers\\";
38 /******************************************************************
39 * StartDoc [GDI.377]
42 INT16 WINAPI StartDoc16( HDC16 hdc, const DOCINFO16 *lpdoc )
44 DOCINFOA docA;
46 docA.cbSize = lpdoc->cbSize;
47 docA.lpszDocName = MapSL(lpdoc->lpszDocName);
48 docA.lpszOutput = MapSL(lpdoc->lpszOutput);
50 if(lpdoc->cbSize >= 14)
51 docA.lpszDatatype = MapSL(lpdoc->lpszDatatype);
52 else
53 docA.lpszDatatype = NULL;
55 if(lpdoc->cbSize >= 18)
56 docA.fwType = lpdoc->fwType;
57 else
58 docA.fwType = 0;
60 return StartDocA(hdc, &docA);
63 /******************************************************************
64 * StartDocA [GDI32.@]
66 * StartDoc calls the STARTDOC Escape with the input data pointing to DocName
67 * and the output data (which is used as a second input parameter).pointing at
68 * the whole docinfo structure. This seems to be an undocumented feature of
69 * the STARTDOC Escape.
71 * Note: we now do it the other way, with the STARTDOC Escape calling StartDoc.
73 INT WINAPI StartDocA(HDC hdc, const DOCINFOA* doc)
75 INT ret = 0;
76 DC *dc = DC_GetDCPtr( hdc );
78 TRACE("DocName = '%s' Output = '%s' Datatype = '%s'\n",
79 doc->lpszDocName, doc->lpszOutput, doc->lpszDatatype);
81 if(!dc) return SP_ERROR;
83 if (dc->funcs->pStartDoc) ret = dc->funcs->pStartDoc( dc, doc );
84 GDI_ReleaseObj( hdc );
85 return ret;
88 /*************************************************************************
89 * StartDocW [GDI32.@]
92 INT WINAPI StartDocW(HDC hdc, const DOCINFOW* doc)
94 DOCINFOA docA;
95 INT ret;
97 docA.cbSize = doc->cbSize;
98 docA.lpszDocName = doc->lpszDocName ?
99 HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszDocName ) : NULL;
100 docA.lpszOutput = doc->lpszOutput ?
101 HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszOutput ) : NULL;
102 docA.lpszDatatype = doc->lpszDatatype ?
103 HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszDatatype ) : NULL;
104 docA.fwType = doc->fwType;
106 ret = StartDocA(hdc, &docA);
108 if(docA.lpszDocName)
109 HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszDocName );
110 if(docA.lpszOutput)
111 HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszOutput );
112 if(docA.lpszDatatype)
113 HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszDatatype );
115 return ret;
118 /******************************************************************
119 * EndDoc [GDI.378]
122 INT16 WINAPI EndDoc16(HDC16 hdc)
124 return EndDoc(hdc);
127 /******************************************************************
128 * EndDoc [GDI32.@]
131 INT WINAPI EndDoc(HDC hdc)
133 INT ret = 0;
134 DC *dc = DC_GetDCPtr( hdc );
135 if(!dc) return SP_ERROR;
137 if (dc->funcs->pEndDoc) ret = dc->funcs->pEndDoc( dc );
138 GDI_ReleaseObj( hdc );
139 return ret;
142 /******************************************************************
143 * StartPage [GDI.379]
146 INT16 WINAPI StartPage16(HDC16 hdc)
148 return StartPage(hdc);
151 /******************************************************************
152 * StartPage [GDI32.@]
155 INT WINAPI StartPage(HDC hdc)
157 INT ret = 1;
158 DC *dc = DC_GetDCPtr( hdc );
159 if(!dc) return SP_ERROR;
161 if(dc->funcs->pStartPage)
162 ret = dc->funcs->pStartPage( dc );
163 else
164 FIXME("stub\n");
165 GDI_ReleaseObj( hdc );
166 return ret;
169 /******************************************************************
170 * EndPage [GDI.380]
173 INT16 WINAPI EndPage16( HDC16 hdc )
175 return EndPage(hdc);
178 /******************************************************************
179 * EndPage [GDI32.@]
182 INT WINAPI EndPage(HDC hdc)
184 INT ret = 0;
185 DC *dc = DC_GetDCPtr( hdc );
186 if(!dc) return SP_ERROR;
188 if (dc->funcs->pEndPage) ret = dc->funcs->pEndPage( dc );
189 GDI_ReleaseObj( hdc );
190 if (!QueryAbort16( hdc, 0 ))
192 EndDoc( hdc );
193 ret = 0;
195 return ret;
198 /******************************************************************************
199 * AbortDoc [GDI.382]
201 INT16 WINAPI AbortDoc16(HDC16 hdc)
203 return AbortDoc(hdc);
206 /******************************************************************************
207 * AbortDoc [GDI32.@]
209 INT WINAPI AbortDoc(HDC hdc)
211 INT ret = 0;
212 DC *dc = DC_GetDCPtr( hdc );
213 if(!dc) return SP_ERROR;
215 if (dc->funcs->pAbortDoc) ret = dc->funcs->pAbortDoc( dc );
216 GDI_ReleaseObj( hdc );
217 return ret;
220 /**********************************************************************
221 * QueryAbort (GDI.155)
223 * Calls the app's AbortProc function if avail.
225 * RETURNS
226 * TRUE if no AbortProc avail or AbortProc wants to continue printing.
227 * FALSE if AbortProc wants to abort printing.
229 BOOL16 WINAPI QueryAbort16(HDC16 hdc, INT16 reserved)
231 BOOL ret = TRUE;
232 DC *dc = DC_GetDCPtr( hdc );
233 ABORTPROC abproc;
235 if(!dc) {
236 ERR("Invalid hdc %04x\n", hdc);
237 return FALSE;
240 abproc = dc->pAbortProc;
241 GDI_ReleaseObj( hdc );
243 if (abproc)
244 ret = abproc(hdc, 0);
245 return ret;
248 /* ### start build ### */
249 extern WORD CALLBACK PRTDRV_CallTo16_word_ww(FARPROC16,WORD,WORD);
250 /* ### stop build ### */
252 /**********************************************************************
253 * call_abort_proc16
255 static BOOL CALLBACK call_abort_proc16( HDC hdc, INT code )
257 ABORTPROC16 proc16;
258 DC *dc = DC_GetDCPtr( hdc );
260 if (!dc) return FALSE;
261 proc16 = dc->pAbortProc16;
262 GDI_ReleaseObj( hdc );
263 if (proc16) return PRTDRV_CallTo16_word_ww( (FARPROC16)proc16, hdc, code );
264 return TRUE;
268 /**********************************************************************
269 * SetAbortProc (GDI.381)
271 INT16 WINAPI SetAbortProc16(HDC16 hdc, ABORTPROC16 abrtprc)
273 DC *dc = DC_GetDCPtr( hdc );
275 if (!dc) return FALSE;
276 dc->pAbortProc16 = abrtprc;
277 GDI_ReleaseObj( hdc );
278 return SetAbortProc( hdc, call_abort_proc16 );
281 /**********************************************************************
282 * SetAbortProc (GDI32.@)
285 INT WINAPI SetAbortProc(HDC hdc, ABORTPROC abrtprc)
287 DC *dc = DC_GetDCPtr( hdc );
289 if (!dc) return FALSE;
290 dc->pAbortProc = abrtprc;
291 GDI_ReleaseObj( hdc );
292 return TRUE;
296 /****************** misc. printer related functions */
299 * The following function should implement a queing system
301 struct hpq
303 struct hpq *next;
304 int tag;
305 int key;
308 static struct hpq *hpqueue;
310 /**********************************************************************
311 * CreatePQ (GDI.230)
314 HPQ16 WINAPI CreatePQ16(INT16 size)
316 #if 0
317 HGLOBAL16 hpq = 0;
318 WORD tmp_size;
319 LPWORD pPQ;
321 tmp_size = size << 2;
322 if (!(hpq = GlobalAlloc16(GMEM_SHARE|GMEM_MOVEABLE, tmp_size + 8)))
323 return 0xffff;
324 pPQ = GlobalLock16(hpq);
325 *pPQ++ = 0;
326 *pPQ++ = tmp_size;
327 *pPQ++ = 0;
328 *pPQ++ = 0;
329 GlobalUnlock16(hpq);
331 return (HPQ16)hpq;
332 #else
333 FIXME("(%d): stub\n",size);
334 return 1;
335 #endif
338 /**********************************************************************
339 * DeletePQ (GDI.235)
342 INT16 WINAPI DeletePQ16(HPQ16 hPQ)
344 return GlobalFree16((HGLOBAL16)hPQ);
347 /**********************************************************************
348 * ExtractPQ (GDI.232)
351 INT16 WINAPI ExtractPQ16(HPQ16 hPQ)
353 struct hpq *queue, *prev, *current, *currentPrev;
354 int key = 0, tag = -1;
355 currentPrev = prev = NULL;
356 queue = current = hpqueue;
357 if (current)
358 key = current->key;
360 while (current)
362 currentPrev = current;
363 current = current->next;
364 if (current)
366 if (current->key < key)
368 queue = current;
369 prev = currentPrev;
373 if (queue)
375 tag = queue->tag;
377 if (prev)
378 prev->next = queue->next;
379 else
380 hpqueue = queue->next;
381 HeapFree(GetProcessHeap(), 0, queue);
384 TRACE("%x got tag %d key %d\n", hPQ, tag, key);
386 return tag;
389 /**********************************************************************
390 * InsertPQ (GDI.233)
393 INT16 WINAPI InsertPQ16(HPQ16 hPQ, INT16 tag, INT16 key)
395 struct hpq *queueItem = HeapAlloc(GetProcessHeap(), 0, sizeof(struct hpq));
396 if(queueItem == NULL) {
397 ERR("Memory exausted!\n");
398 return FALSE;
400 queueItem->next = hpqueue;
401 hpqueue = queueItem;
402 queueItem->key = key;
403 queueItem->tag = tag;
405 FIXME("(%x %d %d): stub???\n", hPQ, tag, key);
406 return TRUE;
409 /**********************************************************************
410 * MinPQ (GDI.231)
413 INT16 WINAPI MinPQ16(HPQ16 hPQ)
415 FIXME("(%x): stub\n", hPQ);
416 return 0;
419 /**********************************************************************
420 * SizePQ (GDI.234)
423 INT16 WINAPI SizePQ16(HPQ16 hPQ, INT16 sizechange)
425 FIXME("(%x %d): stub\n", hPQ, sizechange);
426 return -1;
432 * The following functions implement part of the spooling process to
433 * print manager. I would like to see wine have a version of print managers
434 * that used LPR/LPD. For simplicity print jobs will be sent to a file for
435 * now.
437 typedef struct PRINTJOB
439 char *pszOutput;
440 char *pszTitle;
441 HDC16 hDC;
442 HANDLE16 hHandle;
443 int nIndex;
444 int fd;
445 } PRINTJOB, *PPRINTJOB;
447 #define MAX_PRINT_JOBS 1
448 #define SP_OK 1
450 PPRINTJOB gPrintJobsTable[MAX_PRINT_JOBS];
453 static PPRINTJOB FindPrintJobFromHandle(HANDLE16 hHandle)
455 return gPrintJobsTable[0];
458 static int CreateSpoolFile(LPCSTR pszOutput)
460 int fd=-1;
461 char psCmd[1024];
462 char *psCmdP = psCmd;
464 /* TTD convert the 'output device' into a spool file name */
466 if (pszOutput == NULL || *pszOutput == '\0')
467 return -1;
469 if (!strncmp("LPR:",pszOutput,4))
470 sprintf(psCmd,"|lpr -P%s",pszOutput+4);
471 else
473 HKEY hkey;
474 /* default value */
475 psCmd[0] = 0;
476 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\spooler", &hkey))
478 DWORD type, count = sizeof(psCmd);
479 RegQueryValueExA(hkey, pszOutput, 0, &type, psCmd, &count);
480 RegCloseKey(hkey);
483 TRACE("Got printerSpoolCommand '%s' for output device '%s'\n",
484 psCmd, pszOutput);
485 if (!*psCmd)
486 psCmdP = (char *)pszOutput;
487 else
489 while (*psCmdP && isspace(*psCmdP))
491 psCmdP++;
493 if (!*psCmdP)
494 return -1;
496 if (*psCmdP == '|')
498 int fds[2];
499 if (pipe(fds))
500 return -1;
501 if (fork() == 0)
503 psCmdP++;
505 TRACE("In child need to exec %s\n",psCmdP);
506 close(0);
507 dup2(fds[0],0);
508 close (fds[1]);
509 system(psCmdP);
510 exit(0);
513 close (fds[0]);
514 fd = fds[1];
515 TRACE("Need to execute a cmnd and pipe the output to it\n");
517 else
519 DOS_FULL_NAME fullName;
521 TRACE("Just assume it's a file\n");
524 * The file name can be dos based, we have to find its
525 * Unix correspondant file name
527 DOSFS_GetFullName(psCmdP, FALSE, &fullName);
529 if ((fd = open(fullName.long_name, O_CREAT | O_TRUNC | O_WRONLY , 0600)) < 0)
531 ERR("Failed to create spool file %s (%s)\n",
532 fullName.long_name, strerror(errno));
535 return fd;
538 static int FreePrintJob(HANDLE16 hJob)
540 int nRet = SP_ERROR;
541 PPRINTJOB pPrintJob;
543 pPrintJob = FindPrintJobFromHandle(hJob);
544 if (pPrintJob != NULL)
546 gPrintJobsTable[pPrintJob->nIndex] = NULL;
547 HeapFree(GetProcessHeap(), 0, pPrintJob->pszOutput);
548 HeapFree(GetProcessHeap(), 0, pPrintJob->pszTitle);
549 if (pPrintJob->fd >= 0) close(pPrintJob->fd);
550 HeapFree(GetProcessHeap(), 0, pPrintJob);
551 nRet = SP_OK;
553 return nRet;
556 /**********************************************************************
557 * OpenJob (GDI.240)
560 HPJOB16 WINAPI OpenJob16(LPCSTR lpOutput, LPCSTR lpTitle, HDC16 hDC)
562 HPJOB16 hHandle = (HPJOB16)SP_ERROR;
563 PPRINTJOB pPrintJob;
565 TRACE("'%s' '%s' %04x\n", lpOutput, lpTitle, hDC);
567 pPrintJob = gPrintJobsTable[0];
568 if (pPrintJob == NULL)
570 int fd;
572 /* Try an create a spool file */
573 fd = CreateSpoolFile(lpOutput);
574 if (fd >= 0)
576 pPrintJob = HeapAlloc(GetProcessHeap(), 0, sizeof(PRINTJOB));
577 if(pPrintJob == NULL) {
578 WARN("Memory exausted!\n");
579 return hHandle;
582 hHandle = 1;
584 pPrintJob->pszOutput = HeapAlloc(GetProcessHeap(), 0, strlen(lpOutput)+1);
585 strcpy( pPrintJob->pszOutput, lpOutput );
586 if(lpTitle)
588 pPrintJob->pszTitle = HeapAlloc(GetProcessHeap(), 0, strlen(lpTitle)+1);
589 strcpy( pPrintJob->pszTitle, lpTitle );
591 pPrintJob->hDC = hDC;
592 pPrintJob->fd = fd;
593 pPrintJob->nIndex = 0;
594 pPrintJob->hHandle = hHandle;
595 gPrintJobsTable[pPrintJob->nIndex] = pPrintJob;
598 TRACE("return %04x\n", hHandle);
599 return hHandle;
602 /**********************************************************************
603 * CloseJob (GDI.243)
606 INT16 WINAPI CloseJob16(HPJOB16 hJob)
608 int nRet = SP_ERROR;
609 PPRINTJOB pPrintJob = NULL;
611 TRACE("%04x\n", hJob);
613 pPrintJob = FindPrintJobFromHandle(hJob);
614 if (pPrintJob != NULL)
616 /* Close the spool file */
617 close(pPrintJob->fd);
618 FreePrintJob(hJob);
619 nRet = 1;
621 return nRet;
624 /**********************************************************************
625 * WriteSpool (GDI.241)
628 INT16 WINAPI WriteSpool16(HPJOB16 hJob, LPSTR lpData, INT16 cch)
630 int nRet = SP_ERROR;
631 PPRINTJOB pPrintJob = NULL;
633 TRACE("%04x %08lx %04x\n", hJob, (DWORD)lpData, cch);
635 pPrintJob = FindPrintJobFromHandle(hJob);
636 if (pPrintJob != NULL && pPrintJob->fd >= 0 && cch)
638 if (write(pPrintJob->fd, lpData, cch) != cch)
639 nRet = SP_OUTOFDISK;
640 else
641 nRet = cch;
642 #if 0
643 /* FIXME: We just cannot call 16 bit functions from here, since we
644 * have acquired several locks (DC). And we do not really need to.
646 if (pPrintJob->hDC == 0) {
647 TRACE("hDC == 0 so no QueryAbort\n");
649 else if (!(QueryAbort16(pPrintJob->hDC, (nRet == SP_OUTOFDISK) ? nRet : 0 )))
651 CloseJob16(hJob); /* printing aborted */
652 nRet = SP_APPABORT;
654 #endif
656 return nRet;
659 typedef INT WINAPI (*MSGBOX_PROC)( HWND, LPCSTR, LPCSTR, UINT );
661 /**********************************************************************
662 * WriteDialog (GDI.242)
665 INT16 WINAPI WriteDialog16(HPJOB16 hJob, LPSTR lpMsg, INT16 cchMsg)
667 HMODULE mod;
668 MSGBOX_PROC pMessageBoxA;
669 INT16 ret = 0;
671 TRACE("%04x %04x '%s'\n", hJob, cchMsg, lpMsg);
673 if ((mod = GetModuleHandleA("user32.dll")))
675 if ((pMessageBoxA = (MSGBOX_PROC)GetProcAddress( mod, "MessageBoxA" )))
676 ret = pMessageBoxA(0, lpMsg, "Printing Error", MB_OKCANCEL);
678 return ret;
682 /**********************************************************************
683 * DeleteJob (GDI.244)
686 INT16 WINAPI DeleteJob16(HPJOB16 hJob, INT16 nNotUsed)
688 int nRet;
690 TRACE("%04x\n", hJob);
692 nRet = FreePrintJob(hJob);
693 return nRet;
697 * The following two function would allow a page to be sent to the printer
698 * when it has been processed. For simplicity they havn't been implemented.
699 * This means a whole job has to be processed before it is sent to the printer.
702 /**********************************************************************
703 * StartSpoolPage (GDI.246)
706 INT16 WINAPI StartSpoolPage16(HPJOB16 hJob)
708 FIXME("StartSpoolPage GDI.246 unimplemented\n");
709 return 1;
714 /**********************************************************************
715 * EndSpoolPage (GDI.247)
718 INT16 WINAPI EndSpoolPage16(HPJOB16 hJob)
720 FIXME("EndSpoolPage GDI.247 unimplemented\n");
721 return 1;
725 /**********************************************************************
726 * GetSpoolJob (GDI.245)
729 DWORD WINAPI GetSpoolJob16(int nOption, LONG param)
731 DWORD retval = 0;
732 TRACE("In GetSpoolJob param 0x%lx noption %d\n",param, nOption);
733 return retval;
737 /******************************************************************
738 * DrvGetPrinterDataInternal
740 * Helper for DrvGetPrinterData
742 static DWORD DrvGetPrinterDataInternal(LPSTR RegStr_Printer,
743 LPBYTE lpPrinterData, int cbData, int what)
745 DWORD res = -1;
746 HKEY hkey;
747 DWORD dwType, cbQueryData;
749 if (!(RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey))) {
750 if (what == INT_PD_DEFAULT_DEVMODE) { /* "Default DevMode" */
751 if (!(RegQueryValueExA(hkey, DefaultDevMode, 0, &dwType, 0, &cbQueryData))) {
752 if (!lpPrinterData)
753 res = cbQueryData;
754 else if ((cbQueryData) && (cbQueryData <= cbData)) {
755 cbQueryData = cbData;
756 if (RegQueryValueExA(hkey, DefaultDevMode, 0,
757 &dwType, lpPrinterData, &cbQueryData))
758 res = cbQueryData;
761 } else { /* "Printer Driver" */
762 cbQueryData = 32;
763 RegQueryValueExA(hkey, "Printer Driver", 0,
764 &dwType, lpPrinterData, &cbQueryData);
765 res = cbQueryData;
768 if (hkey) RegCloseKey(hkey);
769 return res;
772 /******************************************************************
773 * DrvGetPrinterData [GDI.282]
776 DWORD WINAPI DrvGetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile,
777 LPDWORD lpType, LPBYTE lpPrinterData,
778 int cbData, LPDWORD lpNeeded)
780 LPSTR RegStr_Printer;
781 HKEY hkey = 0, hkey2 = 0;
782 DWORD res = 0;
783 DWORD dwType, PrinterAttr, cbPrinterAttr, SetData, size;
785 if (HIWORD(lpPrinter))
786 TRACE("printer %s\n",lpPrinter);
787 else
788 TRACE("printer %p\n",lpPrinter);
789 if (HIWORD(lpProfile))
790 TRACE("profile %s\n",lpProfile);
791 else
792 TRACE("profile %p\n",lpProfile);
793 TRACE("lpType %p\n",lpType);
795 if ((!lpPrinter) || (!lpProfile) || (!lpNeeded))
796 return ERROR_INVALID_PARAMETER;
798 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
799 strlen(Printers) + strlen(lpPrinter) + 2);
800 strcpy(RegStr_Printer, Printers);
801 strcat(RegStr_Printer, lpPrinter);
803 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
804 (!strcmp(lpProfile, DefaultDevMode)))) {
805 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData,
806 INT_PD_DEFAULT_DEVMODE);
807 if (size+1) {
808 *lpNeeded = size;
809 if ((lpPrinterData) && (*lpNeeded > cbData))
810 res = ERROR_MORE_DATA;
812 else res = ERROR_INVALID_PRINTER_NAME;
814 else
815 if (((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
816 (!strcmp(lpProfile, PrinterModel)))) {
817 *lpNeeded = 32;
818 if (!lpPrinterData) goto failed;
819 if (cbData < 32) {
820 res = ERROR_MORE_DATA;
821 goto failed;
823 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData,
824 INT_PD_DEFAULT_MODEL);
825 if ((size+1) && (lpType))
826 *lpType = REG_SZ;
827 else
828 res = ERROR_INVALID_PRINTER_NAME;
830 else
832 if ((res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)))
833 goto failed;
834 cbPrinterAttr = 4;
835 if ((res = RegQueryValueExA(hkey, "Attributes", 0,
836 &dwType, (LPBYTE)&PrinterAttr, &cbPrinterAttr)))
837 goto failed;
838 if ((res = RegOpenKeyA(hkey, PrinterDriverData, &hkey2)))
839 goto failed;
840 *lpNeeded = cbData;
841 res = RegQueryValueExA(hkey2, lpProfile, 0,
842 lpType, lpPrinterData, lpNeeded);
843 if ((res != ERROR_CANTREAD) &&
844 ((PrinterAttr &
845 (PRINTER_ATTRIBUTE_ENABLE_BIDI|PRINTER_ATTRIBUTE_NETWORK))
846 == PRINTER_ATTRIBUTE_NETWORK))
848 if (!(res) && (*lpType == REG_DWORD) && (*(LPDWORD)lpPrinterData == -1))
849 res = ERROR_INVALID_DATA;
851 else
853 SetData = -1;
854 RegSetValueExA(hkey2, lpProfile, 0, REG_DWORD, (LPBYTE)&SetData, 4); /* no result returned */
858 failed:
859 if (hkey2) RegCloseKey(hkey2);
860 if (hkey) RegCloseKey(hkey);
861 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
862 return res;
866 /******************************************************************
867 * DrvSetPrinterData [GDI.281]
870 DWORD WINAPI DrvSetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile,
871 DWORD lpType, LPBYTE lpPrinterData,
872 DWORD dwSize)
874 LPSTR RegStr_Printer;
875 HKEY hkey = 0;
876 DWORD res = 0;
878 if (HIWORD(lpPrinter))
879 TRACE("printer %s\n",lpPrinter);
880 else
881 TRACE("printer %p\n",lpPrinter);
882 if (HIWORD(lpProfile))
883 TRACE("profile %s\n",lpProfile);
884 else
885 TRACE("profile %p\n",lpProfile);
886 TRACE("lpType %08lx\n",lpType);
888 if ((!lpPrinter) || (!lpProfile) ||
889 ((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
890 (!strcmp(lpProfile, PrinterModel))))
891 return ERROR_INVALID_PARAMETER;
893 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
894 strlen(Printers) + strlen(lpPrinter) + 2);
895 strcpy(RegStr_Printer, Printers);
896 strcat(RegStr_Printer, lpPrinter);
898 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
899 (!strcmp(lpProfile, DefaultDevMode)))) {
900 if ( RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)
901 != ERROR_SUCCESS ||
902 RegSetValueExA(hkey, DefaultDevMode, 0, REG_BINARY,
903 lpPrinterData, dwSize) != ERROR_SUCCESS )
904 res = ERROR_INVALID_PRINTER_NAME;
906 else
908 strcat(RegStr_Printer, "\\");
910 if( (res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)) ==
911 ERROR_SUCCESS ) {
913 if (!lpPrinterData)
914 res = RegDeleteValueA(hkey, lpProfile);
915 else
916 res = RegSetValueExA(hkey, lpProfile, 0, lpType,
917 lpPrinterData, dwSize);
921 if (hkey) RegCloseKey(hkey);
922 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
923 return res;