Return STATUS_INVALID_INFO_CLASS for non-implemented classes.
[wine/multimedia.git] / dlls / gdi / printdrv.c
blob75afd10e4733050954d0b9418548f1c48221fa29
1 /*
2 * Implementation of some printer driver bits
4 * Copyright 1996 John Harvey
5 * Copyright 1998 Huw Davies
6 * Copyright 1998 Andreas Mohr
7 * Copyright 1999 Klaas van Gend
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "config.h"
25 #include "wine/port.h"
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <signal.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <ctype.h>
33 #include <errno.h>
34 #ifdef HAVE_IO_H
35 # include <io.h>
36 #endif
37 #ifdef HAVE_UNISTD_H
38 # include <unistd.h>
39 #endif
40 #include <fcntl.h>
41 #include "windef.h"
42 #include "winbase.h"
43 #include "winuser.h"
44 #include "wine/winbase16.h"
45 #include "wine/wingdi16.h"
46 #include "winspool.h"
47 #include "winerror.h"
48 #include "winreg.h"
49 #include "wownt32.h"
50 #include "wine/debug.h"
51 #include "gdi.h"
52 #include "gdi_private.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(print);
56 static const char PrinterModel[] = "Printer Model";
57 static const char DefaultDevMode[] = "Default DevMode";
58 static const char PrinterDriverData[] = "PrinterDriverData";
59 static const char Printers[] = "System\\CurrentControlSet\\Control\\Print\\Printers\\";
62 /******************************************************************
63 * StartDocA [GDI32.@]
65 * StartDoc calls the STARTDOC Escape with the input data pointing to DocName
66 * and the output data (which is used as a second input parameter).pointing at
67 * the whole docinfo structure. This seems to be an undocumented feature of
68 * the STARTDOC Escape.
70 * Note: we now do it the other way, with the STARTDOC Escape calling StartDoc.
72 INT WINAPI StartDocW(HDC hdc, const DOCINFOW* doc)
74 INT ret = 0;
75 DC *dc = DC_GetDCPtr( hdc );
77 TRACE("DocName = %s Output = %s Datatype = %s\n",
78 debugstr_w(doc->lpszDocName), debugstr_w(doc->lpszOutput),
79 debugstr_w(doc->lpszDatatype));
81 if(!dc) return SP_ERROR;
83 if (dc->funcs->pStartDoc) ret = dc->funcs->pStartDoc( dc->physDev, doc );
84 GDI_ReleaseObj( hdc );
85 return ret;
88 /*************************************************************************
89 * StartDocA [GDI32.@]
92 INT WINAPI StartDocA(HDC hdc, const DOCINFOA* doc)
94 LPWSTR szDocName = NULL, szOutput = NULL, szDatatype = NULL;
95 DOCINFOW docW;
96 INT ret, len;
98 docW.cbSize = doc->cbSize;
99 if (doc->lpszDocName)
101 len = MultiByteToWideChar(CP_ACP,0,doc->lpszDocName,-1,NULL,0);
102 szDocName = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
103 MultiByteToWideChar(CP_ACP,0,doc->lpszDocName,-1,szDocName,len);
105 if (doc->lpszOutput)
107 len = MultiByteToWideChar(CP_ACP,0,doc->lpszOutput,-1,NULL,0);
108 szOutput = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
109 MultiByteToWideChar(CP_ACP,0,doc->lpszOutput,-1,szOutput,len);
111 if (doc->lpszDatatype)
113 len = MultiByteToWideChar(CP_ACP,0,doc->lpszDatatype,-1,NULL,0);
114 szDatatype = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
115 MultiByteToWideChar(CP_ACP,0,doc->lpszDatatype,-1,szDatatype,len);
118 docW.lpszDocName = szDocName;
119 docW.lpszOutput = szOutput;
120 docW.lpszDatatype = szDatatype;
121 docW.fwType = doc->fwType;
123 ret = StartDocW(hdc, &docW);
125 HeapFree( GetProcessHeap(), 0, szDocName );
126 HeapFree( GetProcessHeap(), 0, szOutput );
127 HeapFree( GetProcessHeap(), 0, szDatatype );
129 return ret;
133 /******************************************************************
134 * EndDoc [GDI32.@]
137 INT WINAPI EndDoc(HDC hdc)
139 INT ret = 0;
140 DC *dc = DC_GetDCPtr( hdc );
141 if(!dc) return SP_ERROR;
143 if (dc->funcs->pEndDoc) ret = dc->funcs->pEndDoc( dc->physDev );
144 GDI_ReleaseObj( hdc );
145 return ret;
149 /******************************************************************
150 * StartPage [GDI32.@]
153 INT WINAPI StartPage(HDC hdc)
155 INT ret = 1;
156 DC *dc = DC_GetDCPtr( hdc );
157 if(!dc) return SP_ERROR;
159 if(dc->funcs->pStartPage)
160 ret = dc->funcs->pStartPage( dc->physDev );
161 else
162 FIXME("stub\n");
163 GDI_ReleaseObj( hdc );
164 return ret;
168 /******************************************************************
169 * EndPage [GDI32.@]
172 INT WINAPI EndPage(HDC hdc)
174 ABORTPROC abort_proc;
175 INT ret = 0;
176 DC *dc = DC_GetDCPtr( hdc );
177 if(!dc) return SP_ERROR;
179 if (dc->funcs->pEndPage) ret = dc->funcs->pEndPage( dc->physDev );
180 abort_proc = dc->pAbortProc;
181 GDI_ReleaseObj( hdc );
182 if (abort_proc && !abort_proc( hdc, 0 ))
184 EndDoc( hdc );
185 ret = 0;
187 return ret;
191 /******************************************************************************
192 * AbortDoc [GDI32.@]
194 INT WINAPI AbortDoc(HDC hdc)
196 INT ret = 0;
197 DC *dc = DC_GetDCPtr( hdc );
198 if(!dc) return SP_ERROR;
200 if (dc->funcs->pAbortDoc) ret = dc->funcs->pAbortDoc( dc->physDev );
201 GDI_ReleaseObj( hdc );
202 return ret;
205 /**********************************************************************
206 * QueryAbort (GDI.155)
208 * Calls the app's AbortProc function if avail.
210 * RETURNS
211 * TRUE if no AbortProc avail or AbortProc wants to continue printing.
212 * FALSE if AbortProc wants to abort printing.
214 BOOL16 WINAPI QueryAbort16(HDC16 hdc16, INT16 reserved)
216 BOOL ret = TRUE;
217 HDC hdc = HDC_32( hdc16 );
218 DC *dc = DC_GetDCPtr( hdc );
219 ABORTPROC abproc;
221 if(!dc) {
222 ERR("Invalid hdc %p\n", hdc);
223 return FALSE;
226 abproc = dc->pAbortProc;
227 GDI_ReleaseObj( hdc );
229 if (abproc)
230 ret = abproc(hdc, 0);
231 return ret;
235 /**********************************************************************
236 * call_abort_proc16
238 static BOOL CALLBACK call_abort_proc16( HDC hdc, INT code )
240 ABORTPROC16 proc16;
241 DC *dc = DC_GetDCPtr( hdc );
243 if (!dc) return FALSE;
244 proc16 = dc->pAbortProc16;
245 GDI_ReleaseObj( hdc );
246 if (proc16)
248 WORD args[2];
249 DWORD ret;
251 args[1] = HDC_16(hdc);
252 args[0] = code;
253 WOWCallback16Ex( (DWORD)proc16, WCB16_PASCAL, sizeof(args), args, &ret );
254 return LOWORD(ret);
256 return TRUE;
260 /**********************************************************************
261 * SetAbortProc (GDI.381)
263 INT16 WINAPI SetAbortProc16(HDC16 hdc16, ABORTPROC16 abrtprc)
265 HDC hdc = HDC_32( hdc16 );
266 DC *dc = DC_GetDCPtr( hdc );
268 if (!dc) return FALSE;
269 dc->pAbortProc16 = abrtprc;
270 GDI_ReleaseObj( hdc );
271 return SetAbortProc( hdc, call_abort_proc16 );
274 /**********************************************************************
275 * SetAbortProc (GDI32.@)
278 INT WINAPI SetAbortProc(HDC hdc, ABORTPROC abrtprc)
280 DC *dc = DC_GetDCPtr( hdc );
282 if (!dc) return FALSE;
283 dc->pAbortProc = abrtprc;
284 GDI_ReleaseObj( hdc );
285 return TRUE;
289 /****************** misc. printer related functions */
292 * The following function should implement a queing system
294 struct hpq
296 struct hpq *next;
297 int tag;
298 int key;
301 static struct hpq *hpqueue;
303 /**********************************************************************
304 * CreatePQ (GDI.230)
307 HPQ16 WINAPI CreatePQ16(INT16 size)
309 #if 0
310 HGLOBAL16 hpq = 0;
311 WORD tmp_size;
312 LPWORD pPQ;
314 tmp_size = size << 2;
315 if (!(hpq = GlobalAlloc16(GMEM_SHARE|GMEM_MOVEABLE, tmp_size + 8)))
316 return 0xffff;
317 pPQ = GlobalLock16(hpq);
318 *pPQ++ = 0;
319 *pPQ++ = tmp_size;
320 *pPQ++ = 0;
321 *pPQ++ = 0;
322 GlobalUnlock16(hpq);
324 return (HPQ16)hpq;
325 #else
326 FIXME("(%d): stub\n",size);
327 return 1;
328 #endif
331 /**********************************************************************
332 * DeletePQ (GDI.235)
335 INT16 WINAPI DeletePQ16(HPQ16 hPQ)
337 return GlobalFree16((HGLOBAL16)hPQ);
340 /**********************************************************************
341 * ExtractPQ (GDI.232)
344 INT16 WINAPI ExtractPQ16(HPQ16 hPQ)
346 struct hpq *queue, *prev, *current, *currentPrev;
347 int key = 0, tag = -1;
348 currentPrev = prev = NULL;
349 queue = current = hpqueue;
350 if (current)
351 key = current->key;
353 while (current)
355 currentPrev = current;
356 current = current->next;
357 if (current)
359 if (current->key < key)
361 queue = current;
362 prev = currentPrev;
366 if (queue)
368 tag = queue->tag;
370 if (prev)
371 prev->next = queue->next;
372 else
373 hpqueue = queue->next;
374 HeapFree(GetProcessHeap(), 0, queue);
377 TRACE("%x got tag %d key %d\n", hPQ, tag, key);
379 return tag;
382 /**********************************************************************
383 * InsertPQ (GDI.233)
386 INT16 WINAPI InsertPQ16(HPQ16 hPQ, INT16 tag, INT16 key)
388 struct hpq *queueItem = HeapAlloc(GetProcessHeap(), 0, sizeof(struct hpq));
389 if(queueItem == NULL) {
390 ERR("Memory exausted!\n");
391 return FALSE;
393 queueItem->next = hpqueue;
394 hpqueue = queueItem;
395 queueItem->key = key;
396 queueItem->tag = tag;
398 FIXME("(%x %d %d): stub???\n", hPQ, tag, key);
399 return TRUE;
402 /**********************************************************************
403 * MinPQ (GDI.231)
406 INT16 WINAPI MinPQ16(HPQ16 hPQ)
408 FIXME("(%x): stub\n", hPQ);
409 return 0;
412 /**********************************************************************
413 * SizePQ (GDI.234)
416 INT16 WINAPI SizePQ16(HPQ16 hPQ, INT16 sizechange)
418 FIXME("(%x %d): stub\n", hPQ, sizechange);
419 return -1;
425 * The following functions implement part of the spooling process to
426 * print manager. I would like to see wine have a version of print managers
427 * that used LPR/LPD. For simplicity print jobs will be sent to a file for
428 * now.
430 typedef struct PRINTJOB
432 char *pszOutput;
433 char *pszTitle;
434 HDC16 hDC;
435 HANDLE16 hHandle;
436 int nIndex;
437 int fd;
438 } PRINTJOB, *PPRINTJOB;
440 #define MAX_PRINT_JOBS 1
441 #define SP_OK 1
443 PPRINTJOB gPrintJobsTable[MAX_PRINT_JOBS];
446 static PPRINTJOB FindPrintJobFromHandle(HANDLE16 hHandle)
448 return gPrintJobsTable[0];
451 static int CreateSpoolFile(LPCSTR pszOutput)
453 int fd=-1;
454 char psCmd[1024];
455 char *psCmdP = psCmd;
456 HKEY hkey;
458 /* TTD convert the 'output device' into a spool file name */
460 if (pszOutput == NULL || *pszOutput == '\0')
461 return -1;
463 psCmd[0] = 0;
464 if (!strncmp("LPR:",pszOutput,4))
466 /* @@ Wine registry key: HKLM\Software\Wine\Wine\Config\spooler */
467 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\spooler", &hkey))
469 DWORD type, count = sizeof(psCmd);
470 RegQueryValueExA(hkey, pszOutput, 0, &type, psCmd, &count);
471 RegCloseKey(hkey);
473 if(psCmd[0] == 0)
474 sprintf(psCmd,"|lpr -P%s",pszOutput+4);
476 else
478 /* @@ Wine registry key: HKLM\Software\Wine\Wine\Config\spooler */
479 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\spooler", &hkey))
481 DWORD type, count = sizeof(psCmd);
482 RegQueryValueExA(hkey, pszOutput, 0, &type, psCmd, &count);
483 RegCloseKey(hkey);
486 TRACE("Got printerSpoolCommand '%s' for output device '%s'\n",
487 psCmd, pszOutput);
488 if (!*psCmd)
489 psCmdP = (char *)pszOutput;
490 else
492 while (*psCmdP && isspace(*psCmdP))
494 psCmdP++;
496 if (!*psCmdP)
497 return -1;
499 TRACE("command: '%s'\n", psCmdP);
500 #ifdef HAVE_FORK
501 if (*psCmdP == '|')
503 int fds[2];
504 if (pipe(fds)) {
505 ERR("pipe() failed!\n");
506 return -1;
508 if (fork() == 0)
510 psCmdP++;
512 TRACE("In child need to exec %s\n",psCmdP);
513 close(0);
514 dup2(fds[0],0);
515 close (fds[1]);
517 /* reset signals that we previously set to SIG_IGN */
518 signal( SIGPIPE, SIG_DFL );
519 signal( SIGCHLD, SIG_DFL );
521 system(psCmdP);
522 exit(0);
525 close (fds[0]);
526 fd = fds[1];
527 TRACE("Need to execute a cmnd and pipe the output to it\n");
529 else
530 #endif
532 char *buffer;
533 WCHAR psCmdPW[MAX_PATH];
535 TRACE("Just assume it's a file\n");
538 * The file name can be dos based, we have to find its
539 * Unix correspondant file name
541 MultiByteToWideChar(CP_ACP, 0, psCmdP, -1, psCmdPW, MAX_PATH);
542 if ((buffer = wine_get_unix_file_name(psCmdPW)))
544 if ((fd = open(buffer, O_CREAT | O_TRUNC | O_WRONLY , 0600)) < 0)
546 ERR("Failed to create spool file '%s' ('%s'). (error %s)\n",
547 buffer, psCmdP, strerror(errno));
549 HeapFree(GetProcessHeap(), 0, buffer);
552 return fd;
555 static int FreePrintJob(HANDLE16 hJob)
557 int nRet = SP_ERROR;
558 PPRINTJOB pPrintJob;
560 pPrintJob = FindPrintJobFromHandle(hJob);
561 if (pPrintJob != NULL)
563 gPrintJobsTable[pPrintJob->nIndex] = NULL;
564 HeapFree(GetProcessHeap(), 0, pPrintJob->pszOutput);
565 HeapFree(GetProcessHeap(), 0, pPrintJob->pszTitle);
566 if (pPrintJob->fd >= 0) close(pPrintJob->fd);
567 HeapFree(GetProcessHeap(), 0, pPrintJob);
568 nRet = SP_OK;
570 return nRet;
573 /**********************************************************************
574 * OpenJob (GDI.240)
577 HPJOB16 WINAPI OpenJob16(LPCSTR lpOutput, LPCSTR lpTitle, HDC16 hDC)
579 HPJOB16 hHandle = (HPJOB16)SP_ERROR;
580 PPRINTJOB pPrintJob;
582 TRACE("'%s' '%s' %04x\n", lpOutput, lpTitle, hDC);
584 pPrintJob = gPrintJobsTable[0];
585 if (pPrintJob == NULL)
587 int fd;
589 /* Try and create a spool file */
590 fd = CreateSpoolFile(lpOutput);
591 if (fd >= 0)
593 pPrintJob = HeapAlloc(GetProcessHeap(), 0, sizeof(PRINTJOB));
594 if(pPrintJob == NULL) {
595 WARN("Memory exausted!\n");
596 return hHandle;
599 hHandle = 1;
601 pPrintJob->pszOutput = HeapAlloc(GetProcessHeap(), 0, strlen(lpOutput)+1);
602 strcpy( pPrintJob->pszOutput, lpOutput );
603 if(lpTitle)
605 pPrintJob->pszTitle = HeapAlloc(GetProcessHeap(), 0, strlen(lpTitle)+1);
606 strcpy( pPrintJob->pszTitle, lpTitle );
608 pPrintJob->hDC = hDC;
609 pPrintJob->fd = fd;
610 pPrintJob->nIndex = 0;
611 pPrintJob->hHandle = hHandle;
612 gPrintJobsTable[pPrintJob->nIndex] = pPrintJob;
615 TRACE("return %04x\n", hHandle);
616 return hHandle;
619 /**********************************************************************
620 * CloseJob (GDI.243)
623 INT16 WINAPI CloseJob16(HPJOB16 hJob)
625 int nRet = SP_ERROR;
626 PPRINTJOB pPrintJob = NULL;
628 TRACE("%04x\n", hJob);
630 pPrintJob = FindPrintJobFromHandle(hJob);
631 if (pPrintJob != NULL)
633 /* Close the spool file */
634 close(pPrintJob->fd);
635 FreePrintJob(hJob);
636 nRet = 1;
638 return nRet;
641 /**********************************************************************
642 * WriteSpool (GDI.241)
645 INT16 WINAPI WriteSpool16(HPJOB16 hJob, LPSTR lpData, INT16 cch)
647 int nRet = SP_ERROR;
648 PPRINTJOB pPrintJob = NULL;
650 TRACE("%04x %08lx %04x\n", hJob, (DWORD)lpData, cch);
652 pPrintJob = FindPrintJobFromHandle(hJob);
653 if (pPrintJob != NULL && pPrintJob->fd >= 0 && cch)
655 if (write(pPrintJob->fd, lpData, cch) != cch)
656 nRet = SP_OUTOFDISK;
657 else
658 nRet = cch;
659 #if 0
660 /* FIXME: We just cannot call 16 bit functions from here, since we
661 * have acquired several locks (DC). And we do not really need to.
663 if (pPrintJob->hDC == 0) {
664 TRACE("hDC == 0 so no QueryAbort\n");
666 else if (!(QueryAbort16(pPrintJob->hDC, (nRet == SP_OUTOFDISK) ? nRet : 0 )))
668 CloseJob16(hJob); /* printing aborted */
669 nRet = SP_APPABORT;
671 #endif
673 return nRet;
676 typedef INT (WINAPI *MSGBOX_PROC)( HWND, LPCSTR, LPCSTR, UINT );
678 /**********************************************************************
679 * WriteDialog (GDI.242)
682 INT16 WINAPI WriteDialog16(HPJOB16 hJob, LPSTR lpMsg, INT16 cchMsg)
684 HMODULE mod;
685 MSGBOX_PROC pMessageBoxA;
686 INT16 ret = 0;
688 TRACE("%04x %04x '%s'\n", hJob, cchMsg, lpMsg);
690 if ((mod = GetModuleHandleA("user32.dll")))
692 if ((pMessageBoxA = (MSGBOX_PROC)GetProcAddress( mod, "MessageBoxA" )))
693 ret = pMessageBoxA(0, lpMsg, "Printing Error", MB_OKCANCEL);
695 return ret;
699 /**********************************************************************
700 * DeleteJob (GDI.244)
703 INT16 WINAPI DeleteJob16(HPJOB16 hJob, INT16 nNotUsed)
705 int nRet;
707 TRACE("%04x\n", hJob);
709 nRet = FreePrintJob(hJob);
710 return nRet;
714 * The following two function would allow a page to be sent to the printer
715 * when it has been processed. For simplicity they havn't been implemented.
716 * This means a whole job has to be processed before it is sent to the printer.
719 /**********************************************************************
720 * StartSpoolPage (GDI.246)
723 INT16 WINAPI StartSpoolPage16(HPJOB16 hJob)
725 FIXME("StartSpoolPage GDI.246 unimplemented\n");
726 return 1;
731 /**********************************************************************
732 * EndSpoolPage (GDI.247)
735 INT16 WINAPI EndSpoolPage16(HPJOB16 hJob)
737 FIXME("EndSpoolPage GDI.247 unimplemented\n");
738 return 1;
742 /**********************************************************************
743 * GetSpoolJob (GDI.245)
746 DWORD WINAPI GetSpoolJob16(int nOption, LONG param)
748 DWORD retval = 0;
749 TRACE("In GetSpoolJob param 0x%lx noption %d\n",param, nOption);
750 return retval;
754 /******************************************************************
755 * DrvGetPrinterDataInternal
757 * Helper for DrvGetPrinterData
759 static DWORD DrvGetPrinterDataInternal(LPSTR RegStr_Printer,
760 LPBYTE lpPrinterData, int cbData, int what)
762 DWORD res = -1;
763 HKEY hkey;
764 DWORD dwType, cbQueryData;
766 if (!(RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey))) {
767 if (what == INT_PD_DEFAULT_DEVMODE) { /* "Default DevMode" */
768 if (!(RegQueryValueExA(hkey, DefaultDevMode, 0, &dwType, 0, &cbQueryData))) {
769 if (!lpPrinterData)
770 res = cbQueryData;
771 else if ((cbQueryData) && (cbQueryData <= cbData)) {
772 cbQueryData = cbData;
773 if (RegQueryValueExA(hkey, DefaultDevMode, 0,
774 &dwType, lpPrinterData, &cbQueryData))
775 res = cbQueryData;
778 } else { /* "Printer Driver" */
779 cbQueryData = 32;
780 RegQueryValueExA(hkey, "Printer Driver", 0,
781 &dwType, lpPrinterData, &cbQueryData);
782 res = cbQueryData;
785 if (hkey) RegCloseKey(hkey);
786 return res;
789 /******************************************************************
790 * DrvGetPrinterData (GDI.282)
793 DWORD WINAPI DrvGetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile,
794 LPDWORD lpType, LPBYTE lpPrinterData,
795 int cbData, LPDWORD lpNeeded)
797 LPSTR RegStr_Printer;
798 HKEY hkey = 0, hkey2 = 0;
799 DWORD res = 0;
800 DWORD dwType, PrinterAttr, cbPrinterAttr, SetData, size;
802 if (HIWORD(lpPrinter))
803 TRACE("printer %s\n",lpPrinter);
804 else
805 TRACE("printer %p\n",lpPrinter);
806 if (HIWORD(lpProfile))
807 TRACE("profile %s\n",lpProfile);
808 else
809 TRACE("profile %p\n",lpProfile);
810 TRACE("lpType %p\n",lpType);
812 if ((!lpPrinter) || (!lpProfile) || (!lpNeeded))
813 return ERROR_INVALID_PARAMETER;
815 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
816 strlen(Printers) + strlen(lpPrinter) + 2);
817 strcpy(RegStr_Printer, Printers);
818 strcat(RegStr_Printer, lpPrinter);
820 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
821 (!strcmp(lpProfile, DefaultDevMode)))) {
822 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData,
823 INT_PD_DEFAULT_DEVMODE);
824 if (size+1) {
825 *lpNeeded = size;
826 if ((lpPrinterData) && (*lpNeeded > cbData))
827 res = ERROR_MORE_DATA;
829 else res = ERROR_INVALID_PRINTER_NAME;
831 else
832 if (((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
833 (!strcmp(lpProfile, PrinterModel)))) {
834 *lpNeeded = 32;
835 if (!lpPrinterData) goto failed;
836 if (cbData < 32) {
837 res = ERROR_MORE_DATA;
838 goto failed;
840 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData,
841 INT_PD_DEFAULT_MODEL);
842 if ((size+1) && (lpType))
843 *lpType = REG_SZ;
844 else
845 res = ERROR_INVALID_PRINTER_NAME;
847 else
849 if ((res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)))
850 goto failed;
851 cbPrinterAttr = 4;
852 if ((res = RegQueryValueExA(hkey, "Attributes", 0,
853 &dwType, (LPBYTE)&PrinterAttr, &cbPrinterAttr)))
854 goto failed;
855 if ((res = RegOpenKeyA(hkey, PrinterDriverData, &hkey2)))
856 goto failed;
857 *lpNeeded = cbData;
858 res = RegQueryValueExA(hkey2, lpProfile, 0,
859 lpType, lpPrinterData, lpNeeded);
860 if ((res != ERROR_CANTREAD) &&
861 ((PrinterAttr &
862 (PRINTER_ATTRIBUTE_ENABLE_BIDI|PRINTER_ATTRIBUTE_NETWORK))
863 == PRINTER_ATTRIBUTE_NETWORK))
865 if (!(res) && (*lpType == REG_DWORD) && (*(LPDWORD)lpPrinterData == -1))
866 res = ERROR_INVALID_DATA;
868 else
870 SetData = -1;
871 RegSetValueExA(hkey2, lpProfile, 0, REG_DWORD, (LPBYTE)&SetData, 4); /* no result returned */
875 failed:
876 if (hkey2) RegCloseKey(hkey2);
877 if (hkey) RegCloseKey(hkey);
878 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
879 return res;
883 /******************************************************************
884 * DrvSetPrinterData (GDI.281)
887 DWORD WINAPI DrvSetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile,
888 DWORD lpType, LPBYTE lpPrinterData,
889 DWORD dwSize)
891 LPSTR RegStr_Printer;
892 HKEY hkey = 0;
893 DWORD res = 0;
895 if (HIWORD(lpPrinter))
896 TRACE("printer %s\n",lpPrinter);
897 else
898 TRACE("printer %p\n",lpPrinter);
899 if (HIWORD(lpProfile))
900 TRACE("profile %s\n",lpProfile);
901 else
902 TRACE("profile %p\n",lpProfile);
903 TRACE("lpType %08lx\n",lpType);
905 if ((!lpPrinter) || (!lpProfile) ||
906 ((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
907 (!strcmp(lpProfile, PrinterModel))))
908 return ERROR_INVALID_PARAMETER;
910 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
911 strlen(Printers) + strlen(lpPrinter) + 2);
912 strcpy(RegStr_Printer, Printers);
913 strcat(RegStr_Printer, lpPrinter);
915 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
916 (!strcmp(lpProfile, DefaultDevMode)))) {
917 if ( RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)
918 != ERROR_SUCCESS ||
919 RegSetValueExA(hkey, DefaultDevMode, 0, REG_BINARY,
920 lpPrinterData, dwSize) != ERROR_SUCCESS )
921 res = ERROR_INVALID_PRINTER_NAME;
923 else
925 strcat(RegStr_Printer, "\\");
927 if( (res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)) ==
928 ERROR_SUCCESS ) {
930 if (!lpPrinterData)
931 res = RegDeleteValueA(hkey, lpProfile);
932 else
933 res = RegSetValueExA(hkey, lpProfile, 0, lpType,
934 lpPrinterData, dwSize);
938 if (hkey) RegCloseKey(hkey);
939 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
940 return res;