2 * Implementation of some printer driver bits
4 * Copyright 1996 John Harvey
16 #define INT_PD_DEFAULT_DEVMODE 1
17 #define INT_PD_DEFAULT_MODEL 2
19 static char PrinterModel
[] = "Printer Model";
20 static char DefaultDevMode
[] = "Default DevMode";
21 static char PrinterDriverData
[] = "PrinterDriverData";
22 static char Printers
[] = "System\\CurrentControlSet\\Control\\Print\\Printers\\";
24 INT16 WINAPI
StartDoc16( HDC16 hdc
, const DOCINFO16
*lpdoc
)
27 TRACE(print
,"(%p)\n", lpdoc
);
28 TRACE(print
,"%d 0x%lx:0x%p 0x%lx:0x%p\n",lpdoc
->cbSize
,
29 lpdoc
->lpszDocName
,PTR_SEG_TO_LIN(lpdoc
->lpszDocName
),
30 lpdoc
->lpszOutput
,PTR_SEG_TO_LIN(lpdoc
->lpszOutput
));
31 TRACE(print
, "%d %s %s\n",lpdoc
->cbSize
,
32 (LPSTR
)PTR_SEG_TO_LIN(lpdoc
->lpszDocName
),
33 (LPSTR
)PTR_SEG_TO_LIN(lpdoc
->lpszOutput
));
34 retVal
= Escape16(hdc
, STARTDOC
, sizeof(DOCINFO16
), lpdoc
->lpszDocName
, 0);
35 TRACE(print
,"Escape16 returned %d\n",retVal
);
39 INT16 WINAPI
EndDoc16(HDC16 hdc
)
41 return Escape16(hdc
, ENDDOC
, 0, 0, 0);
44 WORD
DrvGetPrinterDataInternal(LPSTR RegStr_Printer
, LPBYTE lpPrinterData
, int cbData
)
48 DWORD dwType
, cbQueryData
;
50 if (!(RegOpenKey32A(HKEY_LOCAL_MACHINE
, RegStr_Printer
, &hkey
))) {
51 if (cbData
> 1) { /* "Default DevMode" */
52 if (!(RegQueryValueEx32A(hkey
, DefaultDevMode
, 0, &dwType
, 0, &cbQueryData
))) {
53 if (!lpPrinterData
) res
= cbQueryData
;
55 if ((cbQueryData
) && (cbQueryData
<= cbData
)) {
57 if (RegQueryValueEx32A(hkey
, DefaultDevMode
, 0,
58 &dwType
, lpPrinterData
, &cbQueryData
))
62 else /* "Printer Driver" */
65 RegQueryValueEx32A(hkey
, "Printer Driver", 0,
66 &dwType
, lpPrinterData
, &cbQueryData
);
71 if (hkey
) RegCloseKey(hkey
);
76 DWORD WINAPI
DrvGetPrinterData(LPSTR lpPrinter
, LPSTR lpProfile
,
77 LPDWORD lpType
, LPBYTE lpPrinterData
,
78 int cbData
, LPDWORD lpNeeded
)
81 HKEY hkey
= 0, hkey2
= 0;
83 DWORD dwType
, PrinterAttr
, cbPrinterAttr
, SetData
, size
;
85 if (HIWORD(lpPrinter
))
86 TRACE(print
,"printer %s\n",lpPrinter
);
88 TRACE(print
,"printer %p\n",lpPrinter
);
89 if (HIWORD(lpProfile
))
90 TRACE(print
,"profile %s\n",lpProfile
);
92 TRACE(print
,"profile %p\n",lpProfile
);
93 TRACE(print
,"lpType %p\n",lpType
);
95 if ((!lpPrinter
) || (!lpProfile
) || (!lpNeeded
))
96 return ERROR_INVALID_PARAMETER
;
98 RegStr_Printer
= HeapAlloc(GetProcessHeap(), 0,
99 strlen(Printers
) + strlen(lpPrinter
) + 2);
100 strcpy(RegStr_Printer
, Printers
);
101 strcat(RegStr_Printer
, lpPrinter
);
103 if (((DWORD
)lpProfile
== INT_PD_DEFAULT_DEVMODE
) ||
104 (!lstrcmp32A(lpProfile
, DefaultDevMode
))) {
105 size
= DrvGetPrinterDataInternal(RegStr_Printer
, lpPrinterData
, cbData
);
108 if ((lpPrinterData
) && (*lpNeeded
> cbData
))
109 res
= ERROR_MORE_DATA
;
111 else res
= ERROR_INVALID_PRINTER_NAME
;
114 if (((DWORD
)lpProfile
== INT_PD_DEFAULT_MODEL
) ||
115 (!lstrcmp32A(lpProfile
, PrinterModel
))) {
117 if (!lpPrinterData
) goto failed
;
119 res
= ERROR_MORE_DATA
;
122 size
= DrvGetPrinterDataInternal(RegStr_Printer
, lpPrinterData
, 1);
123 if ((size
+1) && (lpType
))
126 res
= ERROR_INVALID_PRINTER_NAME
;
130 if ((res
= RegOpenKey32A(HKEY_LOCAL_MACHINE
, RegStr_Printer
, &hkey
)))
133 if ((res
= RegQueryValueEx32A(hkey
, "Attributes", 0, &dwType
, (LPBYTE
)&PrinterAttr
, &cbPrinterAttr
)))
135 if ((res
= RegOpenKey32A(hkey
, PrinterDriverData
, &hkey2
)))
138 res
= RegQueryValueEx32A(hkey2
, lpProfile
, 0, lpType
, lpPrinterData
, lpNeeded
);
139 if ((res
!= ERROR_CANTREAD
) && ((PrinterAttr
& (0x800|0x10)) == 0x10))
141 if (!(res
) && (*lpType
== REG_DWORD
) && (*(LPDWORD
)lpPrinterData
== -1))
142 res
= ERROR_INVALID_DATA
;
147 RegSetValueEx32A(hkey2
, lpProfile
, 0, REG_DWORD
, (LPBYTE
)&SetData
, 4); /* no result returned */
152 if (hkey2
) RegCloseKey(hkey2
);
153 if (hkey
) RegCloseKey(hkey
);
154 HeapFree(GetProcessHeap(), 0, RegStr_Printer
);
160 DWORD WINAPI
DrvSetPrinterData(LPSTR lpPrinter
, LPSTR lpProfile
,
161 DWORD lpType
, LPBYTE lpPrinterData
,
164 LPSTR RegStr_Printer
;
168 if (HIWORD(lpPrinter
))
169 TRACE(print
,"printer %s\n",lpPrinter
);
171 TRACE(print
,"printer %p\n",lpPrinter
);
172 if (HIWORD(lpProfile
))
173 TRACE(print
,"profile %s\n",lpProfile
);
175 TRACE(print
,"profile %p\n",lpProfile
);
176 TRACE(print
,"lpType %08lx\n",lpType
);
178 if ((!lpPrinter
) || (!lpProfile
) ||
179 ((DWORD
)lpProfile
== INT_PD_DEFAULT_MODEL
) ||
180 (!lstrcmp32A(lpProfile
, PrinterModel
)))
181 return ERROR_INVALID_PARAMETER
;
183 RegStr_Printer
= HeapAlloc(GetProcessHeap(), 0,
184 strlen(Printers
) + strlen(lpPrinter
) + 2);
185 strcpy(RegStr_Printer
, Printers
);
186 strcat(RegStr_Printer
, lpPrinter
);
188 if (((DWORD
)lpProfile
== INT_PD_DEFAULT_DEVMODE
) ||
189 (!lstrcmp32A(lpProfile
, DefaultDevMode
))) {
190 if (!(RegOpenKey32A(HKEY_LOCAL_MACHINE
, RegStr_Printer
, &hkey
)) ||
191 (RegSetValueEx32A(hkey
, DefaultDevMode
, 0, REG_BINARY
, lpPrinterData
, dwSize
)))
192 res
= ERROR_INVALID_PRINTER_NAME
;
196 strcat(RegStr_Printer
, "\\");
198 if (!(res
= RegOpenKey32A(HKEY_LOCAL_MACHINE
, RegStr_Printer
, &hkey
))) {
201 res
= RegDeleteValue32A(hkey
, lpProfile
);
203 res
= RegSetValueEx32A(hkey
, lpProfile
, 0, lpType
, lpPrinterData
, dwSize
);
207 if (hkey
) RegCloseKey(hkey
);
208 HeapFree(GetProcessHeap(), 0, RegStr_Printer
);
213 INT32 WINAPI
DeviceCapabilities32A(LPCSTR printer
,LPCSTR target
,WORD z
,
214 LPSTR a
,LPDEVMODE32A b
)
216 FIXME(print
,"(%s,%s,%d,%p,%p):stub.\n",printer
,target
,z
,a
,b
);
220 LONG WINAPI
DocumentProperties32A(HWND32 hWnd
,HANDLE32 hPrinter
,
221 LPSTR pDeviceName
, LPDEVMODE32A pDevModeOutput
,
222 LPDEVMODE32A pDevModeInput
,DWORD fMode
)
224 FIXME(print
,"(%d,%d,%s,%p,%p,%ld):stub.\n",
225 hWnd
,hPrinter
,pDeviceName
,pDevModeOutput
,pDevModeInput
,fMode
230 BOOL32 WINAPI
OpenPrinter32A(LPSTR lpPrinterName
,HANDLE32
*phPrinter
,
231 LPPRINTER_DEFAULTS32A pDefault
)
233 FIXME(print
,"(%s,%p,%p):stub.\n",
234 lpPrinterName
, phPrinter
, pDefault
);
235 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
238 BOOL32 WINAPI
EnumPrinters32A(DWORD dwType
, LPSTR lpszName
,
239 DWORD dwLevel
, LPBYTE lpbPrinters
,
240 DWORD cbBuf
, LPDWORD lpdwNeeded
,
241 LPDWORD lpdwReturned
)
243 FIXME(print
,"Nearly empty stub\n");
249 BOOL32 WINAPI
AddMonitor32A(LPCSTR pName
, DWORD Level
, LPBYTE pMonitors
)
251 FIXME(print
, "(%s,%lx,%p):stub!\n", pName
, Level
, pMonitors
);
252 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
258 DeletePrinterDriver32A (LPSTR pName
, LPSTR pEnvironment
, LPSTR pDriverName
)
260 FIXME(print
, "(%s,%s,%s):stub!\n", pName
, pEnvironment
, pDriverName
);
261 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
267 DeleteMonitor32A (LPSTR pName
, LPSTR pEnvironment
, LPSTR pMonitorName
)
269 FIXME(print
, "(%s,%s,%s):stub!\n", pName
, pEnvironment
, pMonitorName
);
270 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
276 DeletePort32A (LPSTR pName
, HWND32 hWnd
, LPSTR pPortName
)
278 FIXME(print
, "(%s,0x%08x,%s):stub!\n", pName
, hWnd
, pPortName
);
279 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);