2 * Implementation of some printer driver bits
4 * Copyright 1996 John Harvey
5 * Copyright 1998 Andreas Mohr
18 static char PrinterModel[] = "Printer Model";
19 static char DefaultDevMode[] = "Default DevMode";
20 static char PrinterDriverData[] = "PrinterDriverData";
21 static char Printers[] = "System\\CurrentControlSet\\Control\\Print\\Printers\\";
23 /******************************************************************
24 * StartDoc16 [GDI.377]
27 INT16 WINAPI StartDoc16( HDC16 hdc, const DOCINFO16 *lpdoc )
30 TRACE(print,"(%p)\n", lpdoc );
31 TRACE(print,"%d 0x%lx:0x%p 0x%lx:0x%p\n",lpdoc->cbSize,
32 lpdoc->lpszDocName,PTR_SEG_TO_LIN(lpdoc->lpszDocName),
33 lpdoc->lpszOutput,PTR_SEG_TO_LIN(lpdoc->lpszOutput));
34 TRACE(print, "%d %s %s\n",lpdoc->cbSize,
35 (LPSTR)PTR_SEG_TO_LIN(lpdoc->lpszDocName),
36 (LPSTR)PTR_SEG_TO_LIN(lpdoc->lpszOutput));
37 retVal = Escape16(hdc, STARTDOC,
38 strlen((LPSTR)PTR_SEG_TO_LIN(lpdoc->lpszDocName)), lpdoc->lpszDocName, 0);
39 TRACE(print,"Escape16 returned %d\n",retVal);
43 /******************************************************************
44 * StartDoc32A [GDI32.347]
47 INT32 WINAPI StartDoc32A(HDC32 hdc ,const DOCINFO32A* doc)
50 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
51 return 0; /* failure*/
54 /******************************************************************
55 * StartPage32 [GDI32.349]
58 INT32 WINAPI StartPage32(HDC32 hdc)
61 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
62 return 0; /* failure*/
65 /******************************************************************
66 * EndPage32 [GDI32.77]
69 INT32 WINAPI EndPage32(HDC32 hdc)
72 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
73 return 0; /* failure*/
76 /******************************************************************
80 INT16 WINAPI EndDoc16(HDC16 hdc)
82 return Escape16(hdc, ENDDOC, 0, 0, 0);
85 /******************************************************************
89 INT32 WINAPI EndDoc32(HDC32 hdc)
92 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
93 return 0; /* failure*/
96 /******************************************************************
97 * DrvGetPrinterDataInternal
99 * Helper for DrvGetPrinterData
101 static DWORD DrvGetPrinterDataInternal(LPSTR RegStr_Printer,
102 LPBYTE lpPrinterData, int cbData)
106 DWORD dwType, cbQueryData;
108 if (!(RegOpenKey32A(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey))) {
109 if (cbData > 1) { /* "Default DevMode" */
110 if (!(RegQueryValueEx32A(hkey, DefaultDevMode, 0, &dwType, 0, &cbQueryData))) {
113 else if ((cbQueryData) && (cbQueryData <= cbData)) {
114 cbQueryData = cbData;
115 if (RegQueryValueEx32A(hkey, DefaultDevMode, 0,
116 &dwType, lpPrinterData, &cbQueryData))
120 } else { /* "Printer Driver" */
122 RegQueryValueEx32A(hkey, "Printer Driver", 0,
123 &dwType, lpPrinterData, &cbQueryData);
127 if (hkey) RegCloseKey(hkey);
131 /******************************************************************
132 * DrvGetPrinterData [GDI.282]
135 DWORD WINAPI DrvGetPrinterData(LPSTR lpPrinter, LPSTR lpProfile,
136 LPDWORD lpType, LPBYTE lpPrinterData,
137 int cbData, LPDWORD lpNeeded)
139 LPSTR RegStr_Printer;
140 HKEY hkey = 0, hkey2 = 0;
142 DWORD dwType, PrinterAttr, cbPrinterAttr, SetData, size;
144 if (HIWORD(lpPrinter))
145 TRACE(print,"printer %s\n",lpPrinter);
147 TRACE(print,"printer %p\n",lpPrinter);
148 if (HIWORD(lpProfile))
149 TRACE(print,"profile %s\n",lpProfile);
151 TRACE(print,"profile %p\n",lpProfile);
152 TRACE(print,"lpType %p\n",lpType);
154 if ((!lpPrinter) || (!lpProfile) || (!lpNeeded))
155 return ERROR_INVALID_PARAMETER;
157 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
158 strlen(Printers) + strlen(lpPrinter) + 2);
159 strcpy(RegStr_Printer, Printers);
160 strcat(RegStr_Printer, lpPrinter);
162 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
163 (!strcmp(lpProfile, DefaultDevMode)))) {
164 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData);
167 if ((lpPrinterData) && (*lpNeeded > cbData))
168 res = ERROR_MORE_DATA;
170 else res = ERROR_INVALID_PRINTER_NAME;
173 if (((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
174 (!strcmp(lpProfile, PrinterModel)))) {
176 if (!lpPrinterData) goto failed;
178 res = ERROR_MORE_DATA;
181 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, 1);
182 if ((size+1) && (lpType))
185 res = ERROR_INVALID_PRINTER_NAME;
189 if ((res = RegOpenKey32A(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)))
192 if ((res = RegQueryValueEx32A(hkey, "Attributes", 0,
193 &dwType, (LPBYTE)&PrinterAttr, &cbPrinterAttr)))
195 if ((res = RegOpenKey32A(hkey, PrinterDriverData, &hkey2)))
198 res = RegQueryValueEx32A(hkey2, lpProfile, 0,
199 lpType, lpPrinterData, lpNeeded);
200 if ((res != ERROR_CANTREAD) &&
202 (PRINTER_ATTRIBUTE_ENABLE_BIDI|PRINTER_ATTRIBUTE_NETWORK))
203 == PRINTER_ATTRIBUTE_NETWORK))
205 if (!(res) && (*lpType == REG_DWORD) && (*(LPDWORD)lpPrinterData == -1))
206 res = ERROR_INVALID_DATA;
211 RegSetValueEx32A(hkey2, lpProfile, 0, REG_DWORD, (LPBYTE)&SetData, 4); /* no result returned */
216 if (hkey2) RegCloseKey(hkey2);
217 if (hkey) RegCloseKey(hkey);
218 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
223 /******************************************************************
224 * DrvSetPrinterData [GDI.281]
227 DWORD WINAPI DrvSetPrinterData(LPSTR lpPrinter, LPSTR lpProfile,
228 DWORD lpType, LPBYTE lpPrinterData,
231 LPSTR RegStr_Printer;
235 if (HIWORD(lpPrinter))
236 TRACE(print,"printer %s\n",lpPrinter);
238 TRACE(print,"printer %p\n",lpPrinter);
239 if (HIWORD(lpProfile))
240 TRACE(print,"profile %s\n",lpProfile);
242 TRACE(print,"profile %p\n",lpProfile);
243 TRACE(print,"lpType %08lx\n",lpType);
245 if ((!lpPrinter) || (!lpProfile) ||
246 ((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
247 (!strcmp(lpProfile, PrinterModel))))
248 return ERROR_INVALID_PARAMETER;
250 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
251 strlen(Printers) + strlen(lpPrinter) + 2);
252 strcpy(RegStr_Printer, Printers);
253 strcat(RegStr_Printer, lpPrinter);
255 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
256 (!strcmp(lpProfile, DefaultDevMode)))) {
257 if ( RegOpenKey32A(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)
259 RegSetValueEx32A(hkey, DefaultDevMode, 0, REG_BINARY,
260 lpPrinterData, dwSize) != ERROR_SUCCESS )
261 res = ERROR_INVALID_PRINTER_NAME;
265 strcat(RegStr_Printer, "\\");
267 if( (res = RegOpenKey32A(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)) ==
271 res = RegDeleteValue32A(hkey, lpProfile);
273 res = RegSetValueEx32A(hkey, lpProfile, 0, lpType,
274 lpPrinterData, dwSize);
278 if (hkey) RegCloseKey(hkey);
279 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
284 /******************************************************************
285 * DeviceCapabilities32A [WINSPOOL.151]
288 INT32 WINAPI DeviceCapabilities32A(LPCSTR printer,LPCSTR target,WORD z,
289 LPSTR a,LPDEVMODE32A b)
291 FIXME(print,"(%s,%s,%d,%p,%p):stub.\n",printer,target,z,a,b);
296 /******************************************************************
297 * DocumentProperties32A [WINSPOOL.155]
300 LONG WINAPI DocumentProperties32A(HWND32 hWnd,HANDLE32 hPrinter,
301 LPSTR pDeviceName, LPDEVMODE32A pDevModeOutput,
302 LPDEVMODE32A pDevModeInput,DWORD fMode )
304 FIXME(print,"(%d,%d,%s,%p,%p,%ld):stub.\n",
305 hWnd,hPrinter,pDeviceName,pDevModeOutput,pDevModeInput,fMode
311 /******************************************************************
312 * OpenPrinter32A [WINSPOOL.196]
315 BOOL32 WINAPI OpenPrinter32A(LPSTR lpPrinterName,HANDLE32 *phPrinter,
316 LPPRINTER_DEFAULTS32A pDefault)
318 FIXME(print,"(%s,%p,%p):stub\n",debugstr_a(lpPrinterName), phPrinter,
320 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
324 /******************************************************************
325 * OpenPrinter32W [WINSPOOL.197]
328 BOOL32 WINAPI OpenPrinter32W(LPWSTR lpPrinterName,HANDLE32 *phPrinter,
329 LPPRINTER_DEFAULTS32W pDefault)
331 FIXME(print,"(%s,%p,%p):stub\n",debugstr_w(lpPrinterName), phPrinter,
333 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
337 /******************************************************************
338 * EnumPrinters32A [WINSPOOL.174]
341 BOOL32 WINAPI EnumPrinters32A(DWORD dwType, LPSTR lpszName,
342 DWORD dwLevel, LPBYTE lpbPrinters,
343 DWORD cbBuf, LPDWORD lpdwNeeded,
344 LPDWORD lpdwReturned)
346 FIXME(print,"Nearly empty stub\n");
351 /******************************************************************
352 * EnumPrinters32W [WINSPOOL.175]
355 BOOL32 WINAPI EnumPrinters32W(DWORD dwType, LPWSTR lpszName,
356 DWORD dwLevel, LPBYTE lpbPrinters,
357 DWORD cbBuf, LPDWORD lpdwNeeded,
358 LPDWORD lpdwReturned)
360 FIXME(print,"Nearly empty stub\n");
365 /******************************************************************
366 * AddMonitor32A [WINSPOOL.107]
369 BOOL32 WINAPI AddMonitor32A(LPCSTR pName, DWORD Level, LPBYTE pMonitors)
371 FIXME(print, "(%s,%lx,%p):stub!\n", pName, Level, pMonitors);
372 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
376 /******************************************************************
377 * DeletePrinterDriver32A [WINSPOOL.146]
381 DeletePrinterDriver32A (LPSTR pName, LPSTR pEnvironment, LPSTR pDriverName)
383 FIXME(print,"(%s,%s,%s):stub\n",debugstr_a(pName),debugstr_a(pEnvironment),
384 debugstr_a(pDriverName));
385 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
390 /******************************************************************
391 * DeleteMonitor32A [WINSPOOL.135]
395 DeleteMonitor32A (LPSTR pName, LPSTR pEnvironment, LPSTR pMonitorName)
397 FIXME(print,"(%s,%s,%s):stub\n",debugstr_a(pName),debugstr_a(pEnvironment),
398 debugstr_a(pMonitorName));
399 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
404 /******************************************************************
405 * DeletePort32A [WINSPOOL.137]
409 DeletePort32A (LPSTR pName, HWND32 hWnd, LPSTR pPortName)
411 FIXME(print,"(%s,0x%08x,%s):stub\n",debugstr_a(pName),hWnd,
412 debugstr_a(pPortName));
413 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);