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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
44 #include "wine/winbase16.h"
45 #include "wine/wingdi16.h"
50 #include "wine/debug.h"
51 #include "gdi_private.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(print
);
55 static const char PrinterModel
[] = "Printer Model";
56 static const char DefaultDevMode
[] = "Default DevMode";
57 static const char PrinterDriverData
[] = "PrinterDriverData";
58 static const char Printers
[] = "System\\CurrentControlSet\\Control\\Print\\Printers\\";
60 /******************************************************************
61 * GdiGetSpoolMessage [GDI32.@]
64 DWORD WINAPI
GdiGetSpoolMessage(LPVOID ptr1
, DWORD data2
, LPVOID ptr3
, DWORD data4
)
66 TRACE("(%p 0x%x %p 0x%x) stub\n", ptr1
, data2
, ptr3
, data4
);
67 /* avoid 100% cpu usage with spoolsv.exe from w2k
68 (spoolsv.exe from xp does Sleep 1000/1500/2000 in a loop) */
73 /******************************************************************
74 * GdiInitSpool [GDI32.@]
77 DWORD WINAPI
GdiInitSpool(void)
83 /******************************************************************
86 * StartDoc calls the STARTDOC Escape with the input data pointing to DocName
87 * and the output data (which is used as a second input parameter).pointing at
88 * the whole docinfo structure. This seems to be an undocumented feature of
89 * the STARTDOC Escape.
91 * Note: we now do it the other way, with the STARTDOC Escape calling StartDoc.
93 INT WINAPI
StartDocW(HDC hdc
, const DOCINFOW
* doc
)
96 DC
*dc
= get_dc_ptr( hdc
);
98 TRACE("DocName = %s Output = %s Datatype = %s\n",
99 debugstr_w(doc
->lpszDocName
), debugstr_w(doc
->lpszOutput
),
100 debugstr_w(doc
->lpszDatatype
));
102 if(!dc
) return SP_ERROR
;
104 if (dc
->funcs
->pStartDoc
) ret
= dc
->funcs
->pStartDoc( dc
->physDev
, doc
);
105 release_dc_ptr( dc
);
109 /*************************************************************************
110 * StartDocA [GDI32.@]
113 INT WINAPI
StartDocA(HDC hdc
, const DOCINFOA
* doc
)
115 LPWSTR szDocName
= NULL
, szOutput
= NULL
, szDatatype
= NULL
;
119 docW
.cbSize
= doc
->cbSize
;
120 if (doc
->lpszDocName
)
122 len
= MultiByteToWideChar(CP_ACP
,0,doc
->lpszDocName
,-1,NULL
,0);
123 szDocName
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
124 MultiByteToWideChar(CP_ACP
,0,doc
->lpszDocName
,-1,szDocName
,len
);
128 len
= MultiByteToWideChar(CP_ACP
,0,doc
->lpszOutput
,-1,NULL
,0);
129 szOutput
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
130 MultiByteToWideChar(CP_ACP
,0,doc
->lpszOutput
,-1,szOutput
,len
);
132 if (doc
->lpszDatatype
)
134 len
= MultiByteToWideChar(CP_ACP
,0,doc
->lpszDatatype
,-1,NULL
,0);
135 szDatatype
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
136 MultiByteToWideChar(CP_ACP
,0,doc
->lpszDatatype
,-1,szDatatype
,len
);
139 docW
.lpszDocName
= szDocName
;
140 docW
.lpszOutput
= szOutput
;
141 docW
.lpszDatatype
= szDatatype
;
142 docW
.fwType
= doc
->fwType
;
144 ret
= StartDocW(hdc
, &docW
);
146 HeapFree( GetProcessHeap(), 0, szDocName
);
147 HeapFree( GetProcessHeap(), 0, szOutput
);
148 HeapFree( GetProcessHeap(), 0, szDatatype
);
154 /******************************************************************
158 INT WINAPI
EndDoc(HDC hdc
)
161 DC
*dc
= get_dc_ptr( hdc
);
162 if(!dc
) return SP_ERROR
;
164 if (dc
->funcs
->pEndDoc
) ret
= dc
->funcs
->pEndDoc( dc
->physDev
);
165 release_dc_ptr( dc
);
170 /******************************************************************
171 * StartPage [GDI32.@]
174 INT WINAPI
StartPage(HDC hdc
)
177 DC
*dc
= get_dc_ptr( hdc
);
178 if(!dc
) return SP_ERROR
;
180 if(dc
->funcs
->pStartPage
)
181 ret
= dc
->funcs
->pStartPage( dc
->physDev
);
184 release_dc_ptr( dc
);
189 /******************************************************************
193 INT WINAPI
EndPage(HDC hdc
)
196 DC
*dc
= get_dc_ptr( hdc
);
197 if(!dc
) return SP_ERROR
;
199 if (dc
->funcs
->pEndPage
) ret
= dc
->funcs
->pEndPage( dc
->physDev
);
200 if (dc
->pAbortProc
&& !dc
->pAbortProc( hdc
, 0 ))
205 release_dc_ptr( dc
);
210 /******************************************************************************
213 INT WINAPI
AbortDoc(HDC hdc
)
216 DC
*dc
= get_dc_ptr( hdc
);
217 if(!dc
) return SP_ERROR
;
219 if (dc
->funcs
->pAbortDoc
) ret
= dc
->funcs
->pAbortDoc( dc
->physDev
);
220 release_dc_ptr( dc
);
224 /**********************************************************************
225 * QueryAbort (GDI.155)
227 * Calls the app's AbortProc function if avail.
230 * TRUE if no AbortProc avail or AbortProc wants to continue printing.
231 * FALSE if AbortProc wants to abort printing.
233 BOOL16 WINAPI
QueryAbort16(HDC16 hdc16
, INT16 reserved
)
236 HDC hdc
= HDC_32( hdc16
);
237 DC
*dc
= get_dc_ptr( hdc
);
240 ERR("Invalid hdc %p\n", hdc
);
243 if (dc
->pAbortProc
) ret
= dc
->pAbortProc(hdc
, 0);
244 release_dc_ptr( dc
);
249 /**********************************************************************
252 static BOOL CALLBACK
call_abort_proc16( HDC hdc
, INT code
)
255 DC
*dc
= get_dc_ptr( hdc
);
257 if (!dc
) return FALSE
;
258 proc16
= dc
->pAbortProc16
;
259 release_dc_ptr( dc
);
265 args
[1] = HDC_16(hdc
);
267 WOWCallback16Ex( (DWORD
)proc16
, WCB16_PASCAL
, sizeof(args
), args
, &ret
);
274 /**********************************************************************
275 * SetAbortProc (GDI.381)
277 INT16 WINAPI
SetAbortProc16(HDC16 hdc16
, ABORTPROC16 abrtprc
)
279 HDC hdc
= HDC_32( hdc16
);
280 DC
*dc
= get_dc_ptr( hdc
);
282 if (!dc
) return FALSE
;
283 dc
->pAbortProc16
= abrtprc
;
284 dc
->pAbortProc
= call_abort_proc16
;
285 release_dc_ptr( dc
);
289 /**********************************************************************
290 * SetAbortProc (GDI32.@)
293 INT WINAPI
SetAbortProc(HDC hdc
, ABORTPROC abrtprc
)
295 DC
*dc
= get_dc_ptr( hdc
);
297 if (!dc
) return FALSE
;
298 dc
->pAbortProc
= abrtprc
;
299 release_dc_ptr( dc
);
304 /****************** misc. printer related functions */
307 * The following function should implement a queing system
316 static struct hpq
*hpqueue
;
318 /**********************************************************************
322 HPQ16 WINAPI
CreatePQ16(INT16 size
)
329 tmp_size
= size
<< 2;
330 if (!(hpq
= GlobalAlloc16(GMEM_SHARE
|GMEM_MOVEABLE
, tmp_size
+ 8)))
332 pPQ
= GlobalLock16(hpq
);
341 FIXME("(%d): stub\n",size
);
346 /**********************************************************************
350 INT16 WINAPI
DeletePQ16(HPQ16 hPQ
)
352 return GlobalFree16(hPQ
);
355 /**********************************************************************
356 * ExtractPQ (GDI.232)
359 INT16 WINAPI
ExtractPQ16(HPQ16 hPQ
)
361 struct hpq
*queue
, *prev
, *current
, *currentPrev
;
362 int key
= 0, tag
= -1;
363 currentPrev
= prev
= NULL
;
364 queue
= current
= hpqueue
;
370 currentPrev
= current
;
371 current
= current
->next
;
374 if (current
->key
< key
)
386 prev
->next
= queue
->next
;
388 hpqueue
= queue
->next
;
389 HeapFree(GetProcessHeap(), 0, queue
);
392 TRACE("%x got tag %d key %d\n", hPQ
, tag
, key
);
397 /**********************************************************************
401 INT16 WINAPI
InsertPQ16(HPQ16 hPQ
, INT16 tag
, INT16 key
)
403 struct hpq
*queueItem
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct hpq
));
404 if(queueItem
== NULL
) {
405 ERR("Memory exausted!\n");
408 queueItem
->next
= hpqueue
;
410 queueItem
->key
= key
;
411 queueItem
->tag
= tag
;
413 FIXME("(%x %d %d): stub???\n", hPQ
, tag
, key
);
417 /**********************************************************************
421 INT16 WINAPI
MinPQ16(HPQ16 hPQ
)
423 FIXME("(%x): stub\n", hPQ
);
427 /**********************************************************************
431 INT16 WINAPI
SizePQ16(HPQ16 hPQ
, INT16 sizechange
)
433 FIXME("(%x %d): stub\n", hPQ
, sizechange
);
440 * The following functions implement part of the spooling process to
441 * print manager. I would like to see wine have a version of print managers
442 * that used LPR/LPD. For simplicity print jobs will be sent to a file for
445 typedef struct PRINTJOB
453 } PRINTJOB
, *PPRINTJOB
;
455 #define MAX_PRINT_JOBS 1
458 static PPRINTJOB gPrintJobsTable
[MAX_PRINT_JOBS
];
461 static PPRINTJOB
FindPrintJobFromHandle(HANDLE16 hHandle
)
463 return gPrintJobsTable
[0];
466 static int CreateSpoolFile(LPCSTR pszOutput
)
470 const char *psCmdP
= psCmd
;
473 /* TTD convert the 'output device' into a spool file name */
475 if (pszOutput
== NULL
|| *pszOutput
== '\0')
479 /* @@ Wine registry key: HKCU\Software\Wine\Printing\Spooler */
480 if(!RegOpenKeyA(HKEY_CURRENT_USER
, "Software\\Wine\\Printing\\Spooler", &hkey
))
482 DWORD type
, count
= sizeof(psCmd
);
483 RegQueryValueExA(hkey
, pszOutput
, 0, &type
, (LPBYTE
)psCmd
, &count
);
486 if (!psCmd
[0] && !strncmp("LPR:",pszOutput
,4))
487 sprintf(psCmd
,"|lpr -P'%s'",pszOutput
+4);
489 TRACE("Got printerSpoolCommand '%s' for output device '%s'\n",
495 while (*psCmdP
&& isspace(*psCmdP
))
502 TRACE("command: '%s'\n", psCmdP
);
508 ERR("pipe() failed!\n");
515 TRACE("In child need to exec %s\n",psCmdP
);
520 /* reset signals that we previously set to SIG_IGN */
521 signal( SIGPIPE
, SIG_DFL
);
522 signal( SIGCHLD
, SIG_DFL
);
524 execl("/bin/sh", "/bin/sh", "-c", psCmdP
, (char*)0);
530 TRACE("Need to execute a cmnd and pipe the output to it\n");
536 WCHAR psCmdPW
[MAX_PATH
];
538 TRACE("Just assume it's a file\n");
541 * The file name can be dos based, we have to find its
542 * Unix correspondant file name
544 MultiByteToWideChar(CP_ACP
, 0, psCmdP
, -1, psCmdPW
, MAX_PATH
);
545 if ((buffer
= wine_get_unix_file_name(psCmdPW
)))
547 if ((fd
= open(buffer
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0666)) < 0)
549 ERR("Failed to create spool file '%s' ('%s'). (error %s)\n",
550 buffer
, psCmdP
, strerror(errno
));
552 HeapFree(GetProcessHeap(), 0, buffer
);
558 static int FreePrintJob(HANDLE16 hJob
)
563 pPrintJob
= FindPrintJobFromHandle(hJob
);
564 if (pPrintJob
!= NULL
)
566 gPrintJobsTable
[pPrintJob
->nIndex
] = NULL
;
567 HeapFree(GetProcessHeap(), 0, pPrintJob
->pszOutput
);
568 HeapFree(GetProcessHeap(), 0, pPrintJob
->pszTitle
);
569 if (pPrintJob
->fd
>= 0) close(pPrintJob
->fd
);
570 HeapFree(GetProcessHeap(), 0, pPrintJob
);
576 /**********************************************************************
580 HPJOB16 WINAPI
OpenJob16(LPCSTR lpOutput
, LPCSTR lpTitle
, HDC16 hDC
)
582 HPJOB16 hHandle
= (HPJOB16
)SP_ERROR
;
585 TRACE("'%s' '%s' %04x\n", lpOutput
, lpTitle
, hDC
);
587 pPrintJob
= gPrintJobsTable
[0];
588 if (pPrintJob
== NULL
)
592 /* Try and create a spool file */
593 fd
= CreateSpoolFile(lpOutput
);
596 pPrintJob
= HeapAlloc(GetProcessHeap(), 0, sizeof(PRINTJOB
));
597 if(pPrintJob
== NULL
) {
598 WARN("Memory exausted!\n");
604 pPrintJob
->pszOutput
= HeapAlloc(GetProcessHeap(), 0, strlen(lpOutput
)+1);
605 strcpy( pPrintJob
->pszOutput
, lpOutput
);
608 pPrintJob
->pszTitle
= HeapAlloc(GetProcessHeap(), 0, strlen(lpTitle
)+1);
609 strcpy( pPrintJob
->pszTitle
, lpTitle
);
611 pPrintJob
->hDC
= hDC
;
613 pPrintJob
->nIndex
= 0;
614 pPrintJob
->hHandle
= hHandle
;
615 gPrintJobsTable
[pPrintJob
->nIndex
] = pPrintJob
;
618 TRACE("return %04x\n", hHandle
);
622 /**********************************************************************
626 INT16 WINAPI
CloseJob16(HPJOB16 hJob
)
629 PPRINTJOB pPrintJob
= NULL
;
631 TRACE("%04x\n", hJob
);
633 pPrintJob
= FindPrintJobFromHandle(hJob
);
634 if (pPrintJob
!= NULL
)
636 /* Close the spool file */
637 close(pPrintJob
->fd
);
644 /**********************************************************************
645 * WriteSpool (GDI.241)
648 INT16 WINAPI
WriteSpool16(HPJOB16 hJob
, LPSTR lpData
, INT16 cch
)
651 PPRINTJOB pPrintJob
= NULL
;
653 TRACE("%04x %p %04x\n", hJob
, lpData
, cch
);
655 pPrintJob
= FindPrintJobFromHandle(hJob
);
656 if (pPrintJob
!= NULL
&& pPrintJob
->fd
>= 0 && cch
)
658 if (write(pPrintJob
->fd
, lpData
, cch
) != cch
)
663 /* FIXME: We just cannot call 16 bit functions from here, since we
664 * have acquired several locks (DC). And we do not really need to.
666 if (pPrintJob
->hDC
== 0) {
667 TRACE("hDC == 0 so no QueryAbort\n");
669 else if (!(QueryAbort16(pPrintJob
->hDC
, (nRet
== SP_OUTOFDISK
) ? nRet
: 0 )))
671 CloseJob16(hJob
); /* printing aborted */
679 typedef INT (WINAPI
*MSGBOX_PROC
)( HWND
, LPCSTR
, LPCSTR
, UINT
);
681 /**********************************************************************
682 * WriteDialog (GDI.242)
685 INT16 WINAPI
WriteDialog16(HPJOB16 hJob
, LPSTR lpMsg
, INT16 cchMsg
)
688 MSGBOX_PROC pMessageBoxA
;
691 TRACE("%04x %04x '%s'\n", hJob
, cchMsg
, lpMsg
);
693 if ((mod
= GetModuleHandleA("user32.dll")))
695 if ((pMessageBoxA
= (MSGBOX_PROC
)GetProcAddress( mod
, "MessageBoxA" )))
696 ret
= pMessageBoxA(0, lpMsg
, "Printing Error", MB_OKCANCEL
);
702 /**********************************************************************
703 * DeleteJob (GDI.244)
706 INT16 WINAPI
DeleteJob16(HPJOB16 hJob
, INT16 nNotUsed
)
710 TRACE("%04x\n", hJob
);
712 nRet
= FreePrintJob(hJob
);
717 * The following two function would allow a page to be sent to the printer
718 * when it has been processed. For simplicity they haven't been implemented.
719 * This means a whole job has to be processed before it is sent to the printer.
722 /**********************************************************************
723 * StartSpoolPage (GDI.246)
726 INT16 WINAPI
StartSpoolPage16(HPJOB16 hJob
)
728 FIXME("StartSpoolPage GDI.246 unimplemented\n");
734 /**********************************************************************
735 * EndSpoolPage (GDI.247)
738 INT16 WINAPI
EndSpoolPage16(HPJOB16 hJob
)
740 FIXME("EndSpoolPage GDI.247 unimplemented\n");
745 /**********************************************************************
746 * GetSpoolJob (GDI.245)
749 DWORD WINAPI
GetSpoolJob16(int nOption
, LONG param
)
752 TRACE("In GetSpoolJob param 0x%x noption %d\n",param
, nOption
);
757 /******************************************************************
758 * DrvGetPrinterDataInternal
760 * Helper for DrvGetPrinterData
762 static DWORD
DrvGetPrinterDataInternal(LPSTR RegStr_Printer
,
763 LPBYTE lpPrinterData
, int cbData
, int what
)
767 DWORD dwType
, cbQueryData
;
769 if (!(RegOpenKeyA(HKEY_LOCAL_MACHINE
, RegStr_Printer
, &hkey
))) {
770 if (what
== INT_PD_DEFAULT_DEVMODE
) { /* "Default DevMode" */
771 if (!(RegQueryValueExA(hkey
, DefaultDevMode
, 0, &dwType
, 0, &cbQueryData
))) {
774 else if ((cbQueryData
) && (cbQueryData
<= cbData
)) {
775 cbQueryData
= cbData
;
776 if (RegQueryValueExA(hkey
, DefaultDevMode
, 0,
777 &dwType
, lpPrinterData
, &cbQueryData
))
781 } else { /* "Printer Driver" */
783 RegQueryValueExA(hkey
, "Printer Driver", 0,
784 &dwType
, lpPrinterData
, &cbQueryData
);
788 if (hkey
) RegCloseKey(hkey
);
792 /******************************************************************
793 * DrvGetPrinterData (GDI.282)
796 DWORD WINAPI
DrvGetPrinterData16(LPSTR lpPrinter
, LPSTR lpProfile
,
797 LPDWORD lpType
, LPBYTE lpPrinterData
,
798 int cbData
, LPDWORD lpNeeded
)
800 LPSTR RegStr_Printer
;
801 HKEY hkey
= 0, hkey2
= 0;
803 DWORD dwType
, PrinterAttr
, cbPrinterAttr
, SetData
, size
;
805 if (HIWORD(lpPrinter
))
806 TRACE("printer %s\n",lpPrinter
);
808 TRACE("printer %p\n",lpPrinter
);
809 if (HIWORD(lpProfile
))
810 TRACE("profile %s\n",lpProfile
);
812 TRACE("profile %p\n",lpProfile
);
813 TRACE("lpType %p\n",lpType
);
815 if ((!lpPrinter
) || (!lpProfile
) || (!lpNeeded
))
816 return ERROR_INVALID_PARAMETER
;
818 RegStr_Printer
= HeapAlloc(GetProcessHeap(), 0,
819 strlen(Printers
) + strlen(lpPrinter
) + 2);
820 strcpy(RegStr_Printer
, Printers
);
821 strcat(RegStr_Printer
, lpPrinter
);
823 if ((PtrToUlong(lpProfile
) == INT_PD_DEFAULT_DEVMODE
) || (HIWORD(lpProfile
) &&
824 (!strcmp(lpProfile
, DefaultDevMode
)))) {
825 size
= DrvGetPrinterDataInternal(RegStr_Printer
, lpPrinterData
, cbData
,
826 INT_PD_DEFAULT_DEVMODE
);
829 if ((lpPrinterData
) && (*lpNeeded
> cbData
))
830 res
= ERROR_MORE_DATA
;
832 else res
= ERROR_INVALID_PRINTER_NAME
;
835 if ((PtrToUlong(lpProfile
) == INT_PD_DEFAULT_MODEL
) || (HIWORD(lpProfile
) &&
836 (!strcmp(lpProfile
, PrinterModel
)))) {
838 if (!lpPrinterData
) goto failed
;
840 res
= ERROR_MORE_DATA
;
843 size
= DrvGetPrinterDataInternal(RegStr_Printer
, lpPrinterData
, cbData
,
844 INT_PD_DEFAULT_MODEL
);
845 if ((size
+1) && (lpType
))
848 res
= ERROR_INVALID_PRINTER_NAME
;
852 if ((res
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, RegStr_Printer
, &hkey
)))
855 if ((res
= RegQueryValueExA(hkey
, "Attributes", 0,
856 &dwType
, (LPBYTE
)&PrinterAttr
, &cbPrinterAttr
)))
858 if ((res
= RegOpenKeyA(hkey
, PrinterDriverData
, &hkey2
)))
861 res
= RegQueryValueExA(hkey2
, lpProfile
, 0,
862 lpType
, lpPrinterData
, lpNeeded
);
863 if ((res
!= ERROR_CANTREAD
) &&
865 (PRINTER_ATTRIBUTE_ENABLE_BIDI
|PRINTER_ATTRIBUTE_NETWORK
))
866 == PRINTER_ATTRIBUTE_NETWORK
))
868 if (!(res
) && (*lpType
== REG_DWORD
) && (*(LPDWORD
)lpPrinterData
== -1))
869 res
= ERROR_INVALID_DATA
;
874 RegSetValueExA(hkey2
, lpProfile
, 0, REG_DWORD
, (LPBYTE
)&SetData
, 4); /* no result returned */
879 if (hkey2
) RegCloseKey(hkey2
);
880 if (hkey
) RegCloseKey(hkey
);
881 HeapFree(GetProcessHeap(), 0, RegStr_Printer
);
886 /******************************************************************
887 * DrvSetPrinterData (GDI.281)
890 DWORD WINAPI
DrvSetPrinterData16(LPSTR lpPrinter
, LPSTR lpProfile
,
891 DWORD lpType
, LPBYTE lpPrinterData
,
894 LPSTR RegStr_Printer
;
898 if (HIWORD(lpPrinter
))
899 TRACE("printer %s\n",lpPrinter
);
901 TRACE("printer %p\n",lpPrinter
);
902 if (HIWORD(lpProfile
))
903 TRACE("profile %s\n",lpProfile
);
905 TRACE("profile %p\n",lpProfile
);
906 TRACE("lpType %08x\n",lpType
);
908 if ((!lpPrinter
) || (!lpProfile
) ||
909 (PtrToUlong(lpProfile
) == INT_PD_DEFAULT_MODEL
) || (HIWORD(lpProfile
) &&
910 (!strcmp(lpProfile
, PrinterModel
))))
911 return ERROR_INVALID_PARAMETER
;
913 RegStr_Printer
= HeapAlloc(GetProcessHeap(), 0,
914 strlen(Printers
) + strlen(lpPrinter
) + 2);
915 strcpy(RegStr_Printer
, Printers
);
916 strcat(RegStr_Printer
, lpPrinter
);
918 if ((PtrToUlong(lpProfile
) == INT_PD_DEFAULT_DEVMODE
) || (HIWORD(lpProfile
) &&
919 (!strcmp(lpProfile
, DefaultDevMode
)))) {
920 if ( RegOpenKeyA(HKEY_LOCAL_MACHINE
, RegStr_Printer
, &hkey
)
922 RegSetValueExA(hkey
, DefaultDevMode
, 0, REG_BINARY
,
923 lpPrinterData
, dwSize
) != ERROR_SUCCESS
)
924 res
= ERROR_INVALID_PRINTER_NAME
;
928 strcat(RegStr_Printer
, "\\");
930 if( (res
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, RegStr_Printer
, &hkey
)) ==
934 res
= RegDeleteValueA(hkey
, lpProfile
);
936 res
= RegSetValueExA(hkey
, lpProfile
, 0, lpType
,
937 lpPrinterData
, dwSize
);
941 if (hkey
) RegCloseKey(hkey
);
942 HeapFree(GetProcessHeap(), 0, RegStr_Printer
);