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 INT16 WINAPI StartDoc16( HDC16 hdc, const DOCINFO16 *lpdoc )
26 TRACE(print,"(%p)\n", lpdoc );
27 TRACE(print,"%d 0x%lx:0x%p 0x%lx:0x%p\n",lpdoc->cbSize,
28 lpdoc->lpszDocName,PTR_SEG_TO_LIN(lpdoc->lpszDocName),
29 lpdoc->lpszOutput,PTR_SEG_TO_LIN(lpdoc->lpszOutput));
30 TRACE(print, "%d %s %s\n",lpdoc->cbSize,
31 (LPSTR)PTR_SEG_TO_LIN(lpdoc->lpszDocName),
32 (LPSTR)PTR_SEG_TO_LIN(lpdoc->lpszOutput));
33 retVal = Escape16(hdc, STARTDOC,
34 strlen((LPSTR)PTR_SEG_TO_LIN(lpdoc->lpszDocName)), 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 DWORD 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))) {
55 else if ((cbQueryData) && (cbQueryData <= cbData)) {
57 if (RegQueryValueEx32A(hkey, DefaultDevMode, 0,
58 &dwType, lpPrinterData, &cbQueryData))
62 } else { /* "Printer Driver" */
64 RegQueryValueEx32A(hkey, "Printer Driver", 0,
65 &dwType, lpPrinterData, &cbQueryData);
69 if (hkey) RegCloseKey(hkey);
74 DWORD WINAPI DrvGetPrinterData(LPSTR lpPrinter, LPSTR lpProfile,
75 LPDWORD lpType, LPBYTE lpPrinterData,
76 int cbData, LPDWORD lpNeeded)
79 HKEY hkey = 0, hkey2 = 0;
81 DWORD dwType, PrinterAttr, cbPrinterAttr, SetData, size;
83 if (HIWORD(lpPrinter))
84 TRACE(print,"printer %s\n",lpPrinter);
86 TRACE(print,"printer %p\n",lpPrinter);
87 if (HIWORD(lpProfile))
88 TRACE(print,"profile %s\n",lpProfile);
90 TRACE(print,"profile %p\n",lpProfile);
91 TRACE(print,"lpType %p\n",lpType);
93 if ((!lpPrinter) || (!lpProfile) || (!lpNeeded))
94 return ERROR_INVALID_PARAMETER;
96 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
97 strlen(Printers) + strlen(lpPrinter) + 2);
98 strcpy(RegStr_Printer, Printers);
99 strcat(RegStr_Printer, lpPrinter);
101 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
102 (!strcmp(lpProfile, DefaultDevMode)))) {
103 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, cbData);
106 if ((lpPrinterData) && (*lpNeeded > cbData))
107 res = ERROR_MORE_DATA;
109 else res = ERROR_INVALID_PRINTER_NAME;
112 if (((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
113 (!strcmp(lpProfile, PrinterModel)))) {
115 if (!lpPrinterData) goto failed;
117 res = ERROR_MORE_DATA;
120 size = DrvGetPrinterDataInternal(RegStr_Printer, lpPrinterData, 1);
121 if ((size+1) && (lpType))
124 res = ERROR_INVALID_PRINTER_NAME;
128 if ((res = RegOpenKey32A(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)))
131 if ((res = RegQueryValueEx32A(hkey, "Attributes", 0,
132 &dwType, (LPBYTE)&PrinterAttr, &cbPrinterAttr)))
134 if ((res = RegOpenKey32A(hkey, PrinterDriverData, &hkey2)))
137 res = RegQueryValueEx32A(hkey2, lpProfile, 0,
138 lpType, lpPrinterData, lpNeeded);
139 if ((res != ERROR_CANTREAD) &&
141 (PRINTER_ATTRIBUTE_ENABLE_BIDI|PRINTER_ATTRIBUTE_NETWORK))
142 == PRINTER_ATTRIBUTE_NETWORK))
144 if (!(res) && (*lpType == REG_DWORD) && (*(LPDWORD)lpPrinterData == -1))
145 res = ERROR_INVALID_DATA;
150 RegSetValueEx32A(hkey2, lpProfile, 0, REG_DWORD, (LPBYTE)&SetData, 4); /* no result returned */
155 if (hkey2) RegCloseKey(hkey2);
156 if (hkey) RegCloseKey(hkey);
157 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
163 DWORD WINAPI DrvSetPrinterData(LPSTR lpPrinter, LPSTR lpProfile,
164 DWORD lpType, LPBYTE lpPrinterData,
167 LPSTR RegStr_Printer;
171 if (HIWORD(lpPrinter))
172 TRACE(print,"printer %s\n",lpPrinter);
174 TRACE(print,"printer %p\n",lpPrinter);
175 if (HIWORD(lpProfile))
176 TRACE(print,"profile %s\n",lpProfile);
178 TRACE(print,"profile %p\n",lpProfile);
179 TRACE(print,"lpType %08lx\n",lpType);
181 if ((!lpPrinter) || (!lpProfile) ||
182 ((DWORD)lpProfile == INT_PD_DEFAULT_MODEL) || (HIWORD(lpProfile) &&
183 (!strcmp(lpProfile, PrinterModel))))
184 return ERROR_INVALID_PARAMETER;
186 RegStr_Printer = HeapAlloc(GetProcessHeap(), 0,
187 strlen(Printers) + strlen(lpPrinter) + 2);
188 strcpy(RegStr_Printer, Printers);
189 strcat(RegStr_Printer, lpPrinter);
191 if (((DWORD)lpProfile == INT_PD_DEFAULT_DEVMODE) || (HIWORD(lpProfile) &&
192 (!strcmp(lpProfile, DefaultDevMode)))) {
193 if ( RegOpenKey32A(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)
195 RegSetValueEx32A(hkey, DefaultDevMode, 0, REG_BINARY,
196 lpPrinterData, dwSize) != ERROR_SUCCESS )
197 res = ERROR_INVALID_PRINTER_NAME;
201 strcat(RegStr_Printer, "\\");
203 if( (res = RegOpenKey32A(HKEY_LOCAL_MACHINE, RegStr_Printer, &hkey)) ==
207 res = RegDeleteValue32A(hkey, lpProfile);
209 res = RegSetValueEx32A(hkey, lpProfile, 0, lpType,
210 lpPrinterData, dwSize);
214 if (hkey) RegCloseKey(hkey);
215 HeapFree(GetProcessHeap(), 0, RegStr_Printer);
220 INT32 WINAPI DeviceCapabilities32A(LPCSTR printer,LPCSTR target,WORD z,
221 LPSTR a,LPDEVMODE32A b)
223 FIXME(print,"(%s,%s,%d,%p,%p):stub.\n",printer,target,z,a,b);
227 LONG WINAPI DocumentProperties32A(HWND32 hWnd,HANDLE32 hPrinter,
228 LPSTR pDeviceName, LPDEVMODE32A pDevModeOutput,
229 LPDEVMODE32A pDevModeInput,DWORD fMode )
231 FIXME(print,"(%d,%d,%s,%p,%p,%ld):stub.\n",
232 hWnd,hPrinter,pDeviceName,pDevModeOutput,pDevModeInput,fMode
237 BOOL32 WINAPI OpenPrinter32A(LPSTR lpPrinterName,HANDLE32 *phPrinter,
238 LPPRINTER_DEFAULTS32A pDefault)
240 FIXME(print,"(%s,%p,%p):stub\n",debugstr_a(lpPrinterName), phPrinter,
242 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
246 BOOL32 WINAPI EnumPrinters32A(DWORD dwType, LPSTR lpszName,
247 DWORD dwLevel, LPBYTE lpbPrinters,
248 DWORD cbBuf, LPDWORD lpdwNeeded,
249 LPDWORD lpdwReturned)
251 FIXME(print,"Nearly empty stub\n");
256 BOOL32 WINAPI EnumPrinters32W(DWORD dwType, LPWSTR lpszName,
257 DWORD dwLevel, LPBYTE lpbPrinters,
258 DWORD cbBuf, LPDWORD lpdwNeeded,
259 LPDWORD lpdwReturned)
261 FIXME(print,"Nearly empty stub\n");
267 BOOL32 WINAPI AddMonitor32A(LPCSTR pName, DWORD Level, LPBYTE pMonitors)
269 FIXME(print, "(%s,%lx,%p):stub!\n", pName, Level, pMonitors);
270 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
276 DeletePrinterDriver32A (LPSTR pName, LPSTR pEnvironment, LPSTR pDriverName)
278 FIXME(print,"(%s,%s,%s):stub\n",debugstr_a(pName),debugstr_a(pEnvironment),
279 debugstr_a(pDriverName));
280 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
286 DeleteMonitor32A (LPSTR pName, LPSTR pEnvironment, LPSTR pMonitorName)
288 FIXME(print,"(%s,%s,%s):stub\n",debugstr_a(pName),debugstr_a(pEnvironment),
289 debugstr_a(pMonitorName));
290 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
296 DeletePort32A (LPSTR pName, HWND32 hWnd, LPSTR pPortName)
298 FIXME(print,"(%s,0x%08x,%s):stub\n",debugstr_a(pName),hWnd,
299 debugstr_a(pPortName));
300 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);