Replace DOSFS_GetFullName with wine_get_unix_file_name.
[wine/multimedia.git] / dlls / gdi / printdrv.c
blob273f61482405076a858387772870017dea1ad15b
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
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"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <ctype.h>
30 #include <errno.h>
31 #include <unistd.h>
32 #include <fcntl.h>
33 #include "winbase.h"
34 #include "winuser.h"
35 #include "wine/winbase16.h"
36 #include "wine/wingdi16.h"
37 #include "winspool.h"
38 #include "winerror.h"
39 #include "winreg.h"
40 #include "wine/debug.h"
41 #include "gdi.h"
42 #include "heap.h"
43 #include "file.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(print);
47 static char PrinterModel[] = "Printer Model";
48 static char DefaultDevMode[] = "Default DevMode";
49 static char PrinterDriverData[] = "PrinterDriverData";
50 static char Printers[] = "System\\CurrentControlSet\\Control\\Print\\Printers\\";
52 /******************************************************************
53 * StartDoc [GDI.377]
56 INT16 WINAPI StartDoc16( HDC16 hdc, const DOCINFO16 *lpdoc )
58 DOCINFOA docA;
60 docA.cbSize = lpdoc->cbSize;
61 docA.lpszDocName = MapSL(lpdoc->lpszDocName);
62 docA.lpszOutput = MapSL(lpdoc->lpszOutput);
64 if(lpdoc->cbSize >= 14)
65 docA.lpszDatatype = MapSL(lpdoc->lpszDatatype);
66 else
67 docA.lpszDatatype = NULL;
69 if(lpdoc->cbSize >= 18)
70 docA.fwType = lpdoc->fwType;
71 else
72 docA.fwType = 0;
74 return StartDocA(hdc, &docA);
77 /******************************************************************
78 * StartDocA [GDI32.@]
80 * StartDoc calls the STARTDOC Escape with the input data pointing to DocName
81 * and the output data (which is used as a second input parameter).pointing at
82 * the whole docinfo structure. This seems to be an undocumented feature of
83 * the STARTDOC Escape.
85 * Note: we now do it the other way, with the STARTDOC Escape calling StartDoc.
87 INT WINAPI StartDocA(HDC hdc, const DOCINFOA* doc)
89 INT ret = 0;
90 DC *dc = DC_GetDCPtr( hdc );
92 TRACE("DocName = '%s' Output = '%s' Datatype = '%s'\n",
93 doc->lpszDocName, doc->lpszOutput, doc->lpszDatatype);
95 if(!dc) return SP_ERROR;
97 if (dc->funcs->pStartDoc) ret = dc->funcs->pStartDoc( dc->physDev, doc );
98 GDI_ReleaseObj( hdc );
99 return ret;
102 /*************************************************************************
103 * StartDocW [GDI32.@]
106 INT WINAPI StartDocW(HDC hdc, const DOCINFOW* doc)
108 DOCINFOA docA;
109 INT ret;
111 docA.cbSize = doc->cbSize;
112 docA.lpszDocName = doc->lpszDocName ?
113 HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszDocName ) : NULL;
114 docA.lpszOutput = doc->lpszOutput ?
115 HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszOutput ) : NULL;
116 docA.lpszDatatype = doc->lpszDatatype ?
117 HEAP_strdupWtoA( GetProcessHeap(), 0, doc->lpszDatatype ) : NULL;
118 docA.fwType = doc->fwType;
120 ret = StartDocA(hdc, &docA);
122 if(docA.lpszDocName)
123 HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszDocName );
124 if(docA.lpszOutput)
125 HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszOutput );
126 if(docA.lpszDatatype)
127 HeapFree( GetProcessHeap(), 0, (LPSTR)docA.lpszDatatype );
129 return ret;
132 /******************************************************************
133 * EndDoc [GDI.378]
136 INT16 WINAPI EndDoc16(HDC16 hdc)
138 return EndDoc(hdc);
141 /******************************************************************
142 * EndDoc [GDI32.@]
145 INT WINAPI EndDoc(HDC hdc)
147 INT ret = 0;
148 DC *dc = DC_GetDCPtr( hdc );
149 if(!dc) return SP_ERROR;
151 if (dc->funcs->pEndDoc) ret = dc->funcs->pEndDoc( dc->physDev );
152 GDI_ReleaseObj( hdc );
153 return ret;
156 /******************************************************************
157 * StartPage [GDI.379]
160 INT16 WINAPI StartPage16(HDC16 hdc)
162 return StartPage(hdc);
165 /******************************************************************
166 * StartPage [GDI32.@]
169 INT WINAPI StartPage(HDC hdc)
171 INT ret = 1;
172 DC *dc = DC_GetDCPtr( hdc );
173 if(!dc) return SP_ERROR;
175 if(dc->funcs->pStartPage)
176 ret = dc->funcs->pStartPage( dc->physDev );
177 else
178 FIXME("stub\n");
179 GDI_ReleaseObj( hdc );
180 return ret;
183 /******************************************************************
184 * EndPage [GDI.380]
187 INT16 WINAPI EndPage16( HDC16 hdc )
189 return EndPage(hdc);
192 /******************************************************************
193 * EndPage [GDI32.@]
196 INT WINAPI EndPage(HDC hdc)
198 INT ret = 0;
199 DC *dc = DC_GetDCPtr( hdc );
200 if(!dc) return SP_ERROR;
202 if (dc->funcs->pEndPage) ret = dc->funcs->pEndPage( dc->physDev );
203 GDI_ReleaseObj( hdc );
204 if (!QueryAbort16( hdc, 0 ))
206 EndDoc( hdc );
207 ret = 0;
209 return ret;
212 /******************************************************************************
213 * AbortDoc [GDI.382]
215 INT16 WINAPI AbortDoc16(HDC16 hdc)
217 return AbortDoc(hdc);
220 /******************************************************************************
221 * AbortDoc [GDI32.@]
223 INT WINAPI AbortDoc(HDC hdc)
225 INT ret = 0;
226 DC *dc = DC_GetDCPtr( hdc );
227 if(!dc) return SP_ERROR;
229 if (dc->funcs->pAbortDoc) ret = dc->funcs->pAbortDoc( dc->physDev );
230 GDI_ReleaseObj( hdc );
231 return ret;
234 /**********************************************************************
235 * QueryAbort (GDI.155)
237 * Calls the app's AbortProc function if avail.
239 * RETURNS
240 * TRUE if no AbortProc avail or AbortProc wants to continue printing.
241 * FALSE if AbortProc wants to abort printing.
243 BOOL16 WINAPI QueryAbort16(HDC16 hdc, INT16 reserved)
245 BOOL ret = TRUE;
246 DC *dc = DC_GetDCPtr( hdc );
247 ABORTPROC abproc;
249 if(!dc) {
250 ERR("Invalid hdc %04x\n", hdc);
251 return FALSE;
254 abproc = dc->pAbortProc;
255 GDI_ReleaseObj( hdc );
257 if (abproc)
258 ret = abproc(hdc, 0);
259 return ret;
262 /* ### start build ### */
263 extern WORD CALLBACK PRTDRV_CallTo16_word_ww(FARPROC16,WORD,WORD);
264 /* ### stop build ### */
266 /**********************************************************************
267 * call_abort_proc16
269 static BOOL CALLBACK call_abort_proc16( HDC hdc, INT code )
271 ABORTPROC16 proc16;
272 DC *dc = DC_GetDCPtr( hdc );
274 if (!dc) return FALSE;
275 proc16 = dc->pAbortProc16;
276 GDI_ReleaseObj( hdc );
277 if (proc16) return PRTDRV_CallTo16_word_ww( (FARPROC16)proc16, hdc, code );
278 return TRUE;
282 /**********************************************************************
283 * SetAbortProc (GDI.381)
285 INT16 WINAPI SetAbortProc16(HDC16 hdc, ABORTPROC16 abrtprc)
287 DC *dc = DC_GetDCPtr( hdc );
289 if (!dc) return FALSE;
290 dc->pAbortProc16 = abrtprc;
291 GDI_ReleaseObj( hdc );
292 return SetAbortProc( hdc, call_abort_proc16 );
295 /**********************************************************************
296 * SetAbortProc (GDI32.@)
299 INT WINAPI SetAbortProc(HDC hdc, ABORTPROC abrtprc)
301 DC *dc = DC_GetDCPtr( hdc );
303 if (!dc) return FALSE;
304 dc->pAbortProc = abrtprc;
305 GDI_ReleaseObj( hdc );
306 return TRUE;
310 /****************** misc. printer related functions */
313 * The following function should implement a queing system
315 struct hpq
317 struct hpq *next;
318 int tag;
319 int key;
322 static struct hpq *hpqueue;
324 /**********************************************************************
325 * CreatePQ (GDI.230)
328 HPQ16 WINAPI CreatePQ16(INT16 size)
330 #if 0
331 HGLOBAL16 hpq = 0;
332 WORD tmp_size;
333 LPWORD pPQ;
335 tmp_size = size << 2;
336 if (!(hpq = GlobalAlloc16(GMEM_SHARE|GMEM_MOVEABLE, tmp_size + 8)))
337 return 0xffff;
338 pPQ = GlobalLock16(hpq);
339 *pPQ++ = 0;
340 *pPQ++ = tmp_size;
341 *pPQ++ = 0;
342 *pPQ++ = 0;
343 GlobalUnlock16(hpq);
345 return (HPQ16)hpq;
346 #else
347 FIXME("(%d): stub\n",size);
348 return 1;
349 #endif
352 /**********************************************************************
353 * DeletePQ (GDI.235)
356 INT16 WINAPI DeletePQ16(HPQ16 hPQ)
358 return GlobalFree16((HGLOBAL16)hPQ);
361 /**********************************************************************
362 * ExtractPQ (GDI.232)
365 INT16 WINAPI ExtractPQ16(HPQ16 hPQ)
367 struct hpq *queue, *prev, *current, *currentPrev;
368 int key = 0, tag = -1;
369 currentPrev = prev = NULL;
370 queue = current = hpqueue;
371 if (current)
372 key = current->key;
374 while (current)
376 currentPrev = current;
377 current = current->next;
378 if (current)
380 if (current->key < key)
382 queue = current;
383 prev = currentPrev;
387 if (queue)
389 tag = queue->tag;
391 if (prev)
392 prev->next = queue->next;
393 else
394 hpqueue = queue->next;
395 HeapFree(GetProcessHeap(), 0, queue);
398 TRACE("%x got tag %d key %d\n", hPQ, tag, key);
400 return tag;
403 /**********************************************************************
404 * InsertPQ (GDI.233)
407 INT16 WINAPI InsertPQ16(HPQ16 hPQ, INT16 tag, INT16 key)
409 struct hpq *queueItem = HeapAlloc(GetProcessHeap(), 0, sizeof(struct hpq));
410 if(queueItem == NULL) {
411 ERR("Memory exausted!\n");
412 return FALSE;
414 queueItem->next = hpqueue;
415 hpqueue = queueItem;
416 queueItem->key = key;
417 queueItem->tag = tag;
419 FIXME("(%x %d %d): stub???\n", hPQ, tag, key);
420 return TRUE;
423 /**********************************************************************
424 * MinPQ (GDI.231)
427 INT16 WINAPI MinPQ16(HPQ16 hPQ)
429 FIXME("(%x): stub\n", hPQ);
430 return 0;
433 /**********************************************************************
434 * SizePQ (GDI.234)
437 INT16 WINAPI SizePQ16(HPQ16 hPQ, INT16 sizechange)
439 FIXME("(%x %d): stub\n", hPQ, sizechange);
440 return -1;
446 * The following functions implement part of the spooling process to
447 * print manager. I would like to see wine have a version of print managers
448 * that used LPR/LPD. For simplicity print jobs will be sent to a file for
449 * now.
451 typedef struct PRINTJOB
453 char *pszOutput;
454 char *pszTitle;
455 HDC16 hDC;
456 HANDLE16 hHandle;
457 int nIndex;
458 int fd;
459 } PRINTJOB, *PPRINTJOB;
461 #define MAX_PRINT_JOBS 1
462 #define SP_OK 1
464 PPRINTJOB gPrintJobsTable[MAX_PRINT_JOBS];
467 static PPRINTJOB FindPrintJobFromHandle(HANDLE16 hHandle)
469 return gPrintJobsTable[0];
472 static int CreateSpoolFile(LPCSTR pszOutput)
474 int fd=-1;
475 char psCmd[1024];
476 char *psCmdP = psCmd;
478 /* TTD convert the 'output device' into a spool file name */
480 if (pszOutput == NULL || *pszOutput == '\0')
481 return -1;
483 if (!strncmp("LPR:",pszOutput,4))
484 sprintf(psCmd,"|lpr -P%s",pszOutput+4);
485 else
487 HKEY hkey;
488 /* default value */
489 psCmd[0] = 0;
490 if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\spooler", &hkey))
492 DWORD type, count = sizeof(psCmd);
493 RegQueryValueExA(hkey, pszOutput, 0, &type, psCmd, &count);
494 RegCloseKey(hkey);
497 TRACE("Got printerSpoolCommand '%s' for output device '%s'\n",
498 psCmd, pszOutput);
499 if (!*psCmd)
500 psCmdP = (char *)pszOutput;
501 else
503 while (*psCmdP && isspace(*psCmdP))
505 psCmdP++;
507 if (!*psCmdP)
508 return -1;
510 if (*psCmdP == '|')
512 int fds[2];
513 if (pipe(fds))
514 return -1;
515 if (fork() == 0)
517 psCmdP++;
519 TRACE("In child need to exec %s\n",psCmdP);
520 close(0);
521 dup2(fds[0],0);
522 close (fds[1]);
523 system(psCmdP);
524 exit(0);
527 close (fds[0]);
528 fd = fds[1];
529 TRACE("Need to execute a cmnd and pipe the output to it\n");
531 else
533 char buffer[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 wine_get_unix_file_name(psCmdP, buffer, sizeof(buffer));
543 if ((fd = open(buffer, O_CREAT | O_TRUNC | O_WRONLY , 0600)) < 0)
545 ERR("Failed to create spool file '%s' ('%s'). (error %s)\n",
546 buffer, psCmdP, strerror(errno));
549 return fd;
552 static int FreePrintJob(HANDLE16 hJob)
554 int nRet = SP_ERROR;
555 PPRINTJOB pPrintJob;
557 pPrintJob = FindPrintJobFromHandle(hJob);
558 if (pPrintJob != NULL)
560 gPrintJobsTable[pPrintJob->nIndex] = NULL;
561 HeapFree(GetProcessHeap(), 0, pPrintJob->pszOutput);
562 HeapFree(GetProcessHeap(), 0, pPrintJob->pszTitle);
563 if (pPrintJob->fd >= 0) close(pPrintJob->fd);
564 HeapFree(GetProcessHeap(), 0, pPrintJob);
565 nRet = SP_OK;
567 return nRet;
570 /**********************************************************************
571 * OpenJob (GDI.240)
572 * OpenJob16 (GDI32.@)
575 HPJOB16 WINAPI OpenJob16(LPCSTR lpOutput, LPCSTR lpTitle, HDC16 hDC)
577 HPJOB16 hHandle = (HPJOB16)SP_ERROR;
578 PPRINTJOB pPrintJob;
580 TRACE("'%s' '%s' %04x\n", lpOutput, lpTitle, hDC);
582 pPrintJob = gPrintJobsTable[0];
583 if (pPrintJob == NULL)
585 int fd;
587 /* Try and create a spool file */
588 fd = CreateSpoolFile(lpOutput);
589 if (fd >= 0)
591 pPrintJob = HeapAlloc(GetProcessHeap(), 0, sizeof(PRINTJOB));
592 if(pPrintJob == NULL) {
593 WARN("Memory exausted!\n");
594 return hHandle;
597 hHandle = 1;
599 pPrintJob->pszOutput = HeapAlloc(GetProcessHeap(), 0, strlen(lpOutput)+1);
600 strcpy( pPrintJob->pszOutput, lpOutput );
601 if(lpTitle)
603 pPrintJob->pszTitle = HeapAlloc(GetProcessHeap(), 0, strlen(lpTitle)+1);
604 strcpy( pPrintJob->pszTitle, lpTitle );
606 pPrintJob->hDC = hDC;
607 pPrintJob->fd = fd;
608 pPrintJob->nIndex = 0;
609 pPrintJob->hHandle = hHandle;
610 gPrintJobsTable[pPrintJob->nIndex] = pPrintJob;
613 TRACE("return %04x\n", hHandle);
614 return hHandle;
617 /**********************************************************************
618 * CloseJob (GDI.243)
619 * CloseJob16 (GDI32.@)
622 INT16 WINAPI CloseJob16(HPJOB16 hJob)
624 int nRet = SP_ERROR;
625 PPRINTJOB pPrintJob = NULL;
627 TRACE("%04x\n", hJob);
629 pPrintJob = FindPrintJobFromHandle(hJob);
630 if (pPrintJob != NULL)
632 /* Close the spool file */
633 close(pPrintJob->fd);
634 FreePrintJob(hJob);
635 nRet = 1;
637 return nRet;
640 /**********************************************************************
641 * WriteSpool (GDI.241)
642 * WriteSpool16 (GDI32.@)
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)
791 * DrvGetPrinterData16 (GDI32.@)
794 DWORD WINAPI DrvGetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile,
795 LPDWORD lpType, LPBYTE lpPrinterData,
796 int cbData, LPDWORD lpNeeded)
798 LPSTR RegStr_Printer;
799 HKEY hkey = 0, hkey2 = 0;
800 DWORD res = 0;
801 DWORD dwType, PrinterAttr, cbPrinterAttr, SetData, size;
803 if (HIWORD(lpPrinter))
804 TRACE("printer %s\n",lpPrinter);
805 else
806 TRACE("printer %p\n",lpPrinter);
807 if (HIWORD(lpProfile))
808 TRACE("profile %s\n",lpProfile);
809 else
810 TRACE("profile %p\n",lpProfile);
811 TRACE("lpType %p\n",lpType);
813 if ((!lpPrinter) || (!lpProfile) || (!lpNeeded))
814 return ERROR_INVALID_PARAMETER;
816 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
817 strlen(Printers) + strlen(lpPrinter) + 2);
818 strcpy(RegStr_Printer, Printers);
819 strcat(RegStr_Printer, lpPrinter);
821 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
822 (!strcmp(lpProfile, DefaultDevMode)))) {
823 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData,
824 INT_PD_DEFAULT_DEVMODE);
825 if (size+1) {
826 *lpNeeded = size;
827 if ((lpPrinterData) && (*lpNeeded > cbData))
828 res = ERROR_MORE_DATA;
830 else res = ERROR_INVALID_PRINTER_NAME;
832 else
833 if (((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
834 (!strcmp(lpProfile, PrinterModel)))) {
835 *lpNeeded = 32;
836 if (!lpPrinterData) goto failed;
837 if (cbData < 32) {
838 res = ERROR_MORE_DATA;
839 goto failed;
841 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData,
842 INT_PD_DEFAULT_MODEL);
843 if ((size+1) && (lpType))
844 *lpType = REG_SZ;
845 else
846 res = ERROR_INVALID_PRINTER_NAME;
848 else
850 if ((res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)))
851 goto failed;
852 cbPrinterAttr = 4;
853 if ((res = RegQueryValueExA(hkey, "Attributes", 0,
854 &dwType, (LPBYTE)&PrinterAttr, &cbPrinterAttr)))
855 goto failed;
856 if ((res = RegOpenKeyA(hkey, PrinterDriverData, &hkey2)))
857 goto failed;
858 *lpNeeded = cbData;
859 res = RegQueryValueExA(hkey2, lpProfile, 0,
860 lpType, lpPrinterData, lpNeeded);
861 if ((res != ERROR_CANTREAD) &&
862 ((PrinterAttr &
863 (PRINTER_ATTRIBUTE_ENABLE_BIDI|PRINTER_ATTRIBUTE_NETWORK))
864 == PRINTER_ATTRIBUTE_NETWORK))
866 if (!(res) && (*lpType == REG_DWORD) && (*(LPDWORD)lpPrinterData == -1))
867 res = ERROR_INVALID_DATA;
869 else
871 SetData = -1;
872 RegSetValueExA(hkey2, lpProfile, 0, REG_DWORD, (LPBYTE)&SetData, 4); /* no result returned */
876 failed:
877 if (hkey2) RegCloseKey(hkey2);
878 if (hkey) RegCloseKey(hkey);
879 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
880 return res;
884 /******************************************************************
885 * DrvSetPrinterData (GDI.281)
886 * DrvSetPrinterData16 (GDI32.@)
889 DWORD WINAPI DrvSetPrinterData16(LPSTR lpPrinter, LPSTR lpProfile,
890 DWORD lpType, LPBYTE lpPrinterData,
891 DWORD dwSize)
893 LPSTR RegStr_Printer;
894 HKEY hkey = 0;
895 DWORD res = 0;
897 if (HIWORD(lpPrinter))
898 TRACE("printer %s\n",lpPrinter);
899 else
900 TRACE("printer %p\n",lpPrinter);
901 if (HIWORD(lpProfile))
902 TRACE("profile %s\n",lpProfile);
903 else
904 TRACE("profile %p\n",lpProfile);
905 TRACE("lpType %08lx\n",lpType);
907 if ((!lpPrinter) || (!lpProfile) ||
908 ((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
909 (!strcmp(lpProfile, PrinterModel))))
910 return ERROR_INVALID_PARAMETER;
912 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
913 strlen(Printers) + strlen(lpPrinter) + 2);
914 strcpy(RegStr_Printer, Printers);
915 strcat(RegStr_Printer, lpPrinter);
917 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
918 (!strcmp(lpProfile, DefaultDevMode)))) {
919 if ( RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)
920 != ERROR_SUCCESS ||
921 RegSetValueExA(hkey, DefaultDevMode, 0, REG_BINARY,
922 lpPrinterData, dwSize) != ERROR_SUCCESS )
923 res = ERROR_INVALID_PRINTER_NAME;
925 else
927 strcat(RegStr_Printer, "\\");
929 if( (res = RegOpenKeyA(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)) ==
930 ERROR_SUCCESS ) {
932 if (!lpPrinterData)
933 res = RegDeleteValueA(hkey, lpProfile);
934 else
935 res = RegSetValueExA(hkey, lpProfile, 0, lpType,
936 lpPrinterData, dwSize);
940 if (hkey) RegCloseKey(hkey);
941 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
942 return res;