ReactOS 0.4.15-dev-8417-gb6b82fe
printers.c File Reference
#include "precomp.h"
#include <marshalling/printers.h>
#include <strsafe.h>
Include dependency graph for printers.c:

Go to the source code of this file.

Classes

struct  _COMPUI_USERDATA
 

Macros

#define QSM_DOWNLOADINGFONTS   0x0001
 
#define QSM_XPS_PASS   0x0002
 

Typedefs

typedef DWORD(WINAPIDEVICECAPABILITIES) (HANDLE, PWSTR, WORD, PVOID, PDEVMODEW)
 
typedef LONG(WINAPIDEVICEPROPERTYSHEETS) (PPROPSHEETUI_INFO, LPARAM)
 
typedef LONG(WINAPIDOCUMENTPROPERTYSHEETS) (PPROPSHEETUI_INFO, LPARAM)
 
typedef LONG(WINAPICOMMONPROPERTYSHEETUIW) (HWND, PFNPROPSHEETUI, LPARAM, LPDWORD)
 
typedef LONG(WINAPIQUERYCOLORPROFILE) (HANDLE, PDEVMODEW, ULONG, PVOID, ULONG *, FLONG *)
 
typedef BOOL(WINAPISPOOLERPRINTEREVENT) (LPWSTR, int, DWORD, LPARAM)
 
typedef BOOL(WINAPIDEVQUERYPRINT) (HANDLE, LPDEVMODEW, DWORD *)
 
typedef BOOL(WINAPIDEVQUERYPRINTEX) (PDEVQUERYPRINT_INFO)
 
typedef LONG(WINAPICONSTRUCTPRINTERFRIENDLYNAME) (PWSTR, PVOID, LPDWORD)
 
typedef struct _COMPUI_USERDATA COMPUI_USERDATA
 
typedef struct _COMPUI_USERDATAPCOMPUI_USERDATA
 

Functions

LONG WINAPI ConstructPrinterFriendlyName (PWSTR, PVOID, LPDWORD Size)
 
static DWORD _StartDocPrinterSpooled (PSPOOLER_HANDLE pHandle, PDOC_INFO_1W pDocInfo1, PADDJOB_INFO_1W pAddJobInfo1)
 
static DWORD _StartDocPrinterWithRPC (PSPOOLER_HANDLE pHandle, PDOC_INFO_1W pDocInfo1)
 
BOOL WINAPI AbortPrinter (HANDLE hPrinter)
 
HANDLE WINAPI AddPrinterA (PSTR pName, DWORD Level, PBYTE pPrinter)
 
HANDLE WINAPI AddPrinterW (PWSTR pName, DWORD Level, PBYTE pPrinter)
 
BOOL WINAPI ClosePrinter (HANDLE hPrinter)
 
BOOL WINAPI DeletePrinter (HANDLE hPrinter)
 
HMODULE WINAPI LoadPrinterDriver (HANDLE hspool)
 
DWORD WINAPI DeviceCapabilitiesA (LPCSTR pDevice, LPCSTR pPort, WORD fwCapability, LPSTR pOutput, const DEVMODEA *pDevMode)
 
DWORD WINAPI DeviceCapabilitiesW (LPCWSTR pDevice, LPCWSTR pPort, WORD fwCapability, LPWSTR pOutput, const DEVMODEW *pDevMode)
 
BOOL WINAPI DevQueryPrint (HANDLE hPrinter, LPDEVMODEW pDevMode, DWORD *pResID)
 
BOOL WINAPI DevQueryPrintEx (PDEVQUERYPRINT_INFO pDQPInfo)
 
INT WINAPI DocumentEvent (HANDLE hPrinter, HDC hdc, int iEsc, ULONG cbIn, PVOID pvIn, ULONG cbOut, PVOID pvOut)
 
LONG WINAPI DocumentPropertiesA (HWND hWnd, HANDLE hPrinter, LPSTR pDeviceName, PDEVMODEA pDevModeOutput, PDEVMODEA pDevModeInput, DWORD fMode)
 
PRINTER_INFO_9Wget_devmodeW (HANDLE hprn)
 
BOOL FASTCALL CreateUIUserData (ULONG_PTR *puserdata, HANDLE hPrinter)
 
VOID FASTCALL DestroyUIUserData (ULONG_PTR *puserdata)
 
BOOL FASTCALL IntFixUpDevModeNames (PDOCUMENTPROPERTYHEADER pdphdr)
 
LONG WINAPI CreatePrinterFriendlyName (PCOMPUI_USERDATA pcui_ud, LPWSTR pszPrinterName)
 
LONG WINAPI DocumentPropertySheets (PPROPSHEETUI_INFO pCPSUIInfo, LPARAM lparam)
 
LONG WINAPI DevicePropertySheets (PPROPSHEETUI_INFO pCPSUIInfo, LPARAM lparam)
 
LONG WINAPI CallCommonPropertySheetUI (HWND hWnd, PFNPROPSHEETUI pfnPropSheetUI, LPARAM lparam, LPDWORD pResult)
 
LONG WINAPI DocumentPropertiesW (HWND hWnd, HANDLE hPrinter, LPWSTR pDeviceName, PDEVMODEW pDevModeOutput, PDEVMODEW pDevModeInput, DWORD fMode)
 
BOOL WINAPI PrinterProperties (HWND hWnd, HANDLE hPrinter)
 
BOOL WINAPI EndDocPrinter (HANDLE hPrinter)
 
BOOL WINAPI EndPagePrinter (HANDLE hPrinter)
 
BOOL WINAPI EnumPrintersA (DWORD Flags, PSTR Name, DWORD Level, PBYTE pPrinterEnum, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
 
BOOL WINAPI EnumPrintersW (DWORD Flags, PWSTR Name, DWORD Level, PBYTE pPrinterEnum, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
 
BOOL WINAPI FlushPrinter (HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pcWritten, DWORD cSleep)
 
BOOL WINAPI GetDefaultPrinterA (LPSTR pszBuffer, LPDWORD pcchBuffer)
 
BOOL WINAPI GetDefaultPrinterW (LPWSTR pszBuffer, LPDWORD pcchBuffer)
 
BOOL WINAPI GetPrinterA (HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD pcbNeeded)
 
BOOL WINAPI GetPrinterW (HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD pcbNeeded)
 
BOOL WINAPI OpenPrinterA (LPSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSA pDefault)
 
BOOL WINAPI OpenPrinterW (LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault)
 
DWORD WINAPI PrinterMessageBoxA (HANDLE hPrinter, DWORD Error, HWND hWnd, LPSTR pText, LPSTR pCaption, DWORD dwType)
 
DWORD WINAPI PrinterMessageBoxW (HANDLE hPrinter, DWORD Error, HWND hWnd, LPWSTR pText, LPWSTR pCaption, DWORD dwType)
 
BOOL WINAPI QueryColorProfile (HANDLE hPrinter, PDEVMODEW pdevmode, ULONG ulQueryMode, VOID *pvProfileData, ULONG *pcbProfileData, FLONG *pflProfileData)
 
BOOL WINAPI QuerySpoolMode (HANDLE hPrinter, PDWORD downloadFontsFlags, PDWORD dwVersion)
 
DWORD WINAPI QueryRemoteFonts (HANDLE hPrinter, PUNIVERSAL_FONT_ID pufi, ULONG NumberOfUFIs)
 
BOOL WINAPI ReadPrinter (HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pNoBytesRead)
 
BOOL WINAPI ResetPrinterA (HANDLE hPrinter, PPRINTER_DEFAULTSA pDefault)
 
BOOL WINAPI ResetPrinterW (HANDLE hPrinter, PPRINTER_DEFAULTSW pDefault)
 
BOOL WINAPI SeekPrinter (HANDLE hPrinter, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER pliNewPointer, DWORD dwMoveMethod, BOOL bWrite)
 
BOOL WINAPI SetDefaultPrinterA (LPCSTR pszPrinter)
 
BOOL WINAPI SetDefaultPrinterW (LPCWSTR pszPrinter)
 
BOOL WINAPI SetPrinterA (HANDLE hPrinter, DWORD Level, PBYTE pPrinter, DWORD Command)
 
BOOL WINAPI SetPrinterW (HANDLE hPrinter, DWORD Level, PBYTE pPrinter, DWORD Command)
 
BOOL WINAPI SplDriverUnloadComplete (LPWSTR pDriverFile)
 
BOOL WINAPI SpoolerPrinterEvent (LPWSTR pPrinterName, INT DriverEvent, DWORD Flags, LPARAM lParam)
 
INT_PTR CALLBACK file_dlg_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
 
LPWSTR WINAPI StartDocDlgW (HANDLE hPrinter, DOCINFOW *doc)
 
LPSTR WINAPI StartDocDlgA (HANDLE hPrinter, DOCINFOA *doc)
 
DWORD WINAPI StartDocPrinterA (HANDLE hPrinter, DWORD Level, PBYTE pDocInfo)
 
DWORD WINAPI StartDocPrinterW (HANDLE hPrinter, DWORD Level, PBYTE pDocInfo)
 
BOOL WINAPI StartPagePrinter (HANDLE hPrinter)
 
BOOL WINAPI WritePrinter (HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pcWritten)
 
BOOL WINAPI XcvDataW (HANDLE hXcv, PCWSTR pszDataName, PBYTE pInputData, DWORD cbInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded, PDWORD pdwStatus)
 

Variables

HINSTANCE hinstWinSpool
 
static DEVICECAPABILITIES fpDeviceCapabilities
 
static DEVICEPROPERTYSHEETS fpDevicePropertySheets
 
static DOCUMENTPROPERTYSHEETS fpDocumentPropertySheets
 
static COMMONPROPERTYSHEETUIW fpCommonPropertySheetUIW
 
static QUERYCOLORPROFILE fpQueryColorProfile
 
static SPOOLERPRINTEREVENT fpPrinterEvent
 
static DEVQUERYPRINT fpDevQueryPrint
 
static DEVQUERYPRINTEX fpDevQueryPrintEx
 
static CONSTRUCTPRINTERFRIENDLYNAME fpConstructPrinterFriendlyName
 
static const WCHAR wszWindowsKey [] = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows"
 
static const WCHAR wszDeviceValue [] = L"Device"
 
static const WCHAR FILE_Port [] = {'F','I','L','E',':',0}
 

Macro Definition Documentation

◆ QSM_DOWNLOADINGFONTS

#define QSM_DOWNLOADINGFONTS   0x0001

Definition at line 2793 of file printers.c.

◆ QSM_XPS_PASS

#define QSM_XPS_PASS   0x0002

Definition at line 2808 of file printers.c.

Typedef Documentation

◆ COMMONPROPERTYSHEETUIW

typedef LONG(WINAPI * COMMONPROPERTYSHEETUIW) (HWND, PFNPROPSHEETUI, LPARAM, LPDWORD)

Definition at line 26 of file printers.c.

◆ COMPUI_USERDATA

◆ CONSTRUCTPRINTERFRIENDLYNAME

typedef LONG(WINAPI * CONSTRUCTPRINTERFRIENDLYNAME) (PWSTR, PVOID, LPDWORD)

Definition at line 45 of file printers.c.

◆ DEVICECAPABILITIES

typedef DWORD(WINAPI * DEVICECAPABILITIES) (HANDLE, PWSTR, WORD, PVOID, PDEVMODEW)

Definition at line 18 of file printers.c.

◆ DEVICEPROPERTYSHEETS

typedef LONG(WINAPI * DEVICEPROPERTYSHEETS) (PPROPSHEETUI_INFO, LPARAM)

Definition at line 21 of file printers.c.

◆ DEVQUERYPRINT

typedef BOOL(WINAPI * DEVQUERYPRINT) (HANDLE, LPDEVMODEW, DWORD *)

Definition at line 35 of file printers.c.

◆ DEVQUERYPRINTEX

typedef BOOL(WINAPI * DEVQUERYPRINTEX) (PDEVQUERYPRINT_INFO)

Definition at line 38 of file printers.c.

◆ DOCUMENTPROPERTYSHEETS

typedef LONG(WINAPI * DOCUMENTPROPERTYSHEETS) (PPROPSHEETUI_INFO, LPARAM)

Definition at line 23 of file printers.c.

◆ PCOMPUI_USERDATA

◆ QUERYCOLORPROFILE

typedef LONG(WINAPI * QUERYCOLORPROFILE) (HANDLE, PDEVMODEW, ULONG, PVOID, ULONG *, FLONG *)

Definition at line 29 of file printers.c.

◆ SPOOLERPRINTEREVENT

typedef BOOL(WINAPI * SPOOLERPRINTEREVENT) (LPWSTR, int, DWORD, LPARAM)

Definition at line 32 of file printers.c.

Function Documentation

◆ _StartDocPrinterSpooled()

static DWORD _StartDocPrinterSpooled ( PSPOOLER_HANDLE  pHandle,
PDOC_INFO_1W  pDocInfo1,
PADDJOB_INFO_1W  pAddJobInfo1 
)
static

Definition at line 65 of file printers.c.

66{
67 DWORD cbNeeded;
68 DWORD dwErrorCode;
69 PJOB_INFO_1W pJobInfo1 = NULL;
70
71 // Create the spool file.
73 if (pHandle->hSPLFile == INVALID_HANDLE_VALUE)
74 {
75 dwErrorCode = GetLastError();
76 ERR("CreateFileW failed for \"%S\" with error %lu!\n", pAddJobInfo1->Path, dwErrorCode);
77 goto Cleanup;
78 }
79
80 // Get the size of the job information.
81 GetJobW((HANDLE)pHandle, pAddJobInfo1->JobId, 1, NULL, 0, &cbNeeded);
83 {
84 dwErrorCode = GetLastError();
85 ERR("GetJobW failed with error %lu!\n", dwErrorCode);
86 goto Cleanup;
87 }
88
89 // Allocate enough memory for the returned job information.
90 pJobInfo1 = HeapAlloc(hProcessHeap, 0, cbNeeded);
91 if (!pJobInfo1)
92 {
93 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
94 ERR("HeapAlloc failed!\n");
95 goto Cleanup;
96 }
97
98 // Get the job information.
99 if (!GetJobW((HANDLE)pHandle, pAddJobInfo1->JobId, 1, (PBYTE)pJobInfo1, cbNeeded, &cbNeeded))
100 {
101 dwErrorCode = GetLastError();
102 ERR("GetJobW failed with error %lu!\n", dwErrorCode);
103 goto Cleanup;
104 }
105
106 // Add our document information.
107 if (pDocInfo1->pDatatype)
108 pJobInfo1->pDatatype = pDocInfo1->pDatatype;
109
110 pJobInfo1->pDocument = pDocInfo1->pDocName;
111
112 // Set the new job information.
113 if (!SetJobW((HANDLE)pHandle, pAddJobInfo1->JobId, 1, (PBYTE)pJobInfo1, 0))
114 {
115 dwErrorCode = GetLastError();
116 ERR("SetJobW failed with error %lu!\n", dwErrorCode);
117 goto Cleanup;
118 }
119
120 // We were successful!
121 pHandle->dwJobID = pAddJobInfo1->JobId;
122 dwErrorCode = ERROR_SUCCESS;
123
124Cleanup:
125 if (pJobInfo1)
126 HeapFree(hProcessHeap, 0, pJobInfo1);
127
128 return dwErrorCode;
129}
#define ERR(fmt,...)
Definition: precomp.h:57
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE hProcessHeap
Definition: kbswitch.c:37
#define CREATE_ALWAYS
Definition: disk.h:72
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
BYTE * PBYTE
Definition: pedump.c:66
LPWSTR pDatatype
Definition: winspool.h:618
LPWSTR pDocName
Definition: winspool.h:616
HANDLE hSPLFile
Definition: precomp.h:51
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
WINBOOL WINAPI SetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, LPBYTE pJob, DWORD Command)
WINBOOL WINAPI GetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, LPBYTE pJob, DWORD cbBuf, LPDWORD pcbNeeded)

Referenced by StartDocPrinterW().

◆ _StartDocPrinterWithRPC()

static DWORD _StartDocPrinterWithRPC ( PSPOOLER_HANDLE  pHandle,
PDOC_INFO_1W  pDocInfo1 
)
static

Definition at line 132 of file printers.c.

133{
134 DWORD dwErrorCode;
135 WINSPOOL_DOC_INFO_CONTAINER DocInfoContainer;
136
137 DocInfoContainer.Level = 1;
138 DocInfoContainer.DocInfo.pDocInfo1 = (WINSPOOL_DOC_INFO_1*)pDocInfo1;
139
141 {
142 dwErrorCode = _RpcStartDocPrinter(pHandle->hPrinter, &DocInfoContainer, &pHandle->dwJobID);
143 }
145 {
146 dwErrorCode = RpcExceptionCode();
147 ERR("_RpcStartDocPrinter failed with exception code %lu!\n", dwErrorCode);
148 }
150
151 return dwErrorCode;
152}
DWORD _RpcStartDocPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, WINSPOOL_DOC_INFO_CONTAINER *pDocInfoContainer, DWORD *pJobId)
Definition: printers.c:319
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define RpcEndExcept
Definition: rpc.h:128
#define RpcTryExcept
Definition: rpc.h:126
#define RpcExcept(expr)
Definition: rpc.h:127
#define RpcExceptionCode()
Definition: rpc.h:132
DWORD dwJobID
Definition: precomp.h:49
HANDLE hPrinter
Definition: precomp.h:50
WINSPOOL_DOC_INFO_1 * pDocInfo1
Definition: winspool.idl:577
union _WINSPOOL_DOC_INFO_CONTAINER::@3436 DocInfo

Referenced by StartDocPrinterW().

◆ AbortPrinter()

BOOL WINAPI AbortPrinter ( HANDLE  hPrinter)

Definition at line 155 of file printers.c.

156{
157 DWORD dwErrorCode;
158 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
159
160 TRACE("AbortPrinter(%p)\n", hPrinter);
161
162 // Sanity checks.
163 if (!pHandle)
164 {
165 dwErrorCode = ERROR_INVALID_HANDLE;
166 goto Cleanup;
167 }
168
169 pHandle->bTrayIcon = pHandle->bStartedDoc = FALSE;
170
171 if ( pHandle->hSPLFile != INVALID_HANDLE_VALUE && pHandle->bJob )
172 {
173 // Close any open file handle.
174 CloseHandle( pHandle->hSPLFile );
176
177 SetJobW( hPrinter, pHandle->dwJobID, 0, NULL, JOB_CONTROL_DELETE );
178
179 return ScheduleJob( hPrinter, pHandle->dwJobID );
180 }
181
182 // Do the RPC call.
184 {
185 dwErrorCode = _RpcAbortPrinter(&pHandle->hPrinter);
186 }
188 {
189 dwErrorCode = RpcExceptionCode();
190 ERR("_RpcAbortPrinter failed with exception code %lu!\n", dwErrorCode);
191 }
193
194Cleanup:
195 SetLastError(dwErrorCode);
196 return (dwErrorCode == ERROR_SUCCESS);
197}
DWORD _RpcAbortPrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:12
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define TRACE(s)
Definition: solgame.cpp:4
BOOL bStartedDoc
Definition: precomp.h:41
BOOL bTrayIcon
Definition: precomp.h:45
struct _SPOOLER_HANDLE * PSPOOLER_HANDLE
#define JOB_CONTROL_DELETE
Definition: winspool.h:334
WINBOOL WINAPI ScheduleJob(HANDLE hPrinter, DWORD JobId)
Definition: jobs.c:56

◆ AddPrinterA()

HANDLE WINAPI AddPrinterA ( PSTR  pName,
DWORD  Level,
PBYTE  pPrinter 
)

Definition at line 200 of file printers.c.

201{
202 UNICODE_STRING pNameW, usBuffer;
203 PWSTR pwstrNameW;
204 PRINTER_INFO_2W *ppi2w = (PRINTER_INFO_2W*)pPrinter;
205 PRINTER_INFO_2A *ppi2a = (PRINTER_INFO_2A*)pPrinter;
206 HANDLE ret = NULL;
207 PWSTR pwszPrinterName = NULL;
208 PWSTR pwszServerName = NULL;
209 PWSTR pwszShareName = NULL;
210 PWSTR pwszPortName = NULL;
211 PWSTR pwszDriverName = NULL;
212 PWSTR pwszComment = NULL;
213 PWSTR pwszLocation = NULL;
214 PWSTR pwszSepFile = NULL;
215 PWSTR pwszPrintProcessor = NULL;
216 PWSTR pwszDatatype = NULL;
217 PWSTR pwszParameters = NULL;
218 PDEVMODEW pdmw = NULL;
219
220 TRACE("AddPrinterA(%s, %d, %p)\n", debugstr_a(pName), Level, pPrinter);
221
222 if(Level != 2)
223 {
224 ERR("Level = %d, unsupported!\n", Level);
226 return NULL;
227 }
228
229 pwstrNameW = AsciiToUnicode(&pNameW,pName);
230
231 if (ppi2a->pShareName)
232 {
233 pwszShareName = AsciiToUnicode(&usBuffer, ppi2a->pShareName);
234 if (!(ppi2w->pShareName = pwszShareName)) goto Cleanup;
235 }
236 if (ppi2a->pPortName)
237 {
238 pwszPortName = AsciiToUnicode(&usBuffer, ppi2a->pPortName);
239 if (!(ppi2w->pPortName = pwszPortName)) goto Cleanup;
240 }
241 if (ppi2a->pDriverName)
242 {
243 pwszDriverName = AsciiToUnicode(&usBuffer, ppi2a->pDriverName);
244 if (!(ppi2w->pDriverName = pwszDriverName)) goto Cleanup;
245 }
246 if (ppi2a->pComment)
247 {
248 pwszComment = AsciiToUnicode(&usBuffer, ppi2a->pComment);
249 if (!(ppi2w->pComment = pwszComment)) goto Cleanup;
250 }
251 if (ppi2a->pLocation)
252 {
253 pwszLocation = AsciiToUnicode(&usBuffer, ppi2a->pLocation);
254 if (!(ppi2w->pLocation = pwszLocation)) goto Cleanup;
255 }
256 if (ppi2a->pSepFile)
257 {
258 pwszSepFile = AsciiToUnicode(&usBuffer, ppi2a->pSepFile);
259 if (!(ppi2w->pSepFile = pwszSepFile)) goto Cleanup;
260 }
261 if (ppi2a->pServerName)
262 {
263 pwszPrintProcessor = AsciiToUnicode(&usBuffer, ppi2a->pPrintProcessor);
264 if (!(ppi2w->pPrintProcessor = pwszPrintProcessor)) goto Cleanup;
265 }
266 if (ppi2a->pDatatype)
267 {
268 pwszDatatype = AsciiToUnicode(&usBuffer, ppi2a->pDatatype);
269 if (!(ppi2w->pDatatype = pwszDatatype)) goto Cleanup;
270 }
271 if (ppi2a->pParameters)
272 {
273 pwszParameters = AsciiToUnicode(&usBuffer, ppi2a->pParameters);
274 if (!(ppi2w->pParameters = pwszParameters)) goto Cleanup;
275 }
276 if ( ppi2a->pDevMode )
277 {
279 ppi2w->pDevMode = pdmw;
280 }
281 if (ppi2a->pServerName)
282 {
283 pwszServerName = AsciiToUnicode(&usBuffer, ppi2a->pServerName);
284 if (!(ppi2w->pPrinterName = pwszServerName)) goto Cleanup;
285 }
286 if (ppi2a->pPrinterName)
287 {
288 pwszPrinterName = AsciiToUnicode(&usBuffer, ppi2a->pPrinterName);
289 if (!(ppi2w->pPrinterName = pwszPrinterName)) goto Cleanup;
290 }
291
292 ret = AddPrinterW(pwstrNameW, Level, (LPBYTE)ppi2w);
293
294Cleanup:
295 if (pdmw) HeapFree(hProcessHeap, 0, pdmw);
296 if (pwszPrinterName) HeapFree(hProcessHeap, 0, pwszPrinterName);
297 if (pwszServerName) HeapFree(hProcessHeap, 0, pwszServerName);
298 if (pwszShareName) HeapFree(hProcessHeap, 0, pwszShareName);
299 if (pwszPortName) HeapFree(hProcessHeap, 0, pwszPortName);
300 if (pwszDriverName) HeapFree(hProcessHeap, 0, pwszDriverName);
301 if (pwszComment) HeapFree(hProcessHeap, 0, pwszComment);
302 if (pwszLocation) HeapFree(hProcessHeap, 0, pwszLocation);
303 if (pwszSepFile) HeapFree(hProcessHeap, 0, pwszSepFile);
304 if (pwszPrintProcessor) HeapFree(hProcessHeap, 0, pwszPrintProcessor);
305 if (pwszDatatype) HeapFree(hProcessHeap, 0, pwszDatatype);
306 if (pwszParameters) HeapFree(hProcessHeap, 0, pwszParameters);
307
308 RtlFreeUnicodeString(&pNameW);
309 return ret;
310}
HANDLE WINAPI AddPrinterW(PWSTR pName, DWORD Level, PBYTE pPrinter)
Definition: printers.c:313
void RosConvertAnsiDevModeToUnicodeDevmode(PDEVMODEA pDevModeInput, PDEVMODEW *pDevModeOutput)
Definition: devmode.c:285
#define debugstr_a
Definition: kernel32.h:31
wstring AsciiToUnicode(const char *AsciiString)
Definition: tools.cpp:220
static LPSTR pName
Definition: security.c:75
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
LPDEVMODEA pDevMode
Definition: winspool.h:45
LPSTR pDriverName
Definition: winspool.h:42
LPSTR pParameters
Definition: winspool.h:49
LPSTR pPrinterName
Definition: winspool.h:39
LPSTR pDatatype
Definition: winspool.h:48
LPSTR pPortName
Definition: winspool.h:41
LPSTR pSepFile
Definition: winspool.h:46
LPSTR pServerName
Definition: winspool.h:38
LPSTR pComment
Definition: winspool.h:43
LPSTR pLocation
Definition: winspool.h:44
LPSTR pShareName
Definition: winspool.h:40
LPSTR pPrintProcessor
Definition: winspool.h:47
LPWSTR pPrintProcessor
Definition: winspool.h:71
LPWSTR pSepFile
Definition: winspool.h:70
LPWSTR pDatatype
Definition: winspool.h:72
LPWSTR pLocation
Definition: winspool.h:68
LPWSTR pPrinterName
Definition: winspool.h:63
LPWSTR pComment
Definition: winspool.h:67
LPWSTR pPortName
Definition: winspool.h:65
LPWSTR pDriverName
Definition: winspool.h:66
LPWSTR pShareName
Definition: winspool.h:64
LPDEVMODEW pDevMode
Definition: winspool.h:69
LPWSTR pParameters
Definition: winspool.h:73
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char * LPBYTE
Definition: typedefs.h:53
int ret
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56

◆ AddPrinterW()

HANDLE WINAPI AddPrinterW ( PWSTR  pName,
DWORD  Level,
PBYTE  pPrinter 
)

Definition at line 313 of file printers.c.

314{
315 DWORD dwErrorCode;
316 WINSPOOL_PRINTER_CONTAINER PrinterContainer;
317 WINSPOOL_DEVMODE_CONTAINER DevModeContainer;
318 WINSPOOL_SECURITY_CONTAINER SecurityContainer;
320 DWORD size;
321 HANDLE hPrinter = NULL, hHandle = NULL;
322 PSPOOLER_HANDLE pHandle = NULL;
323
324 TRACE("AddPrinterW(%S, %lu, %p)\n", pName, Level, pPrinter);
325
326 DevModeContainer.cbBuf = 0;
327 DevModeContainer.pDevMode = NULL;
328
329 SecurityContainer.cbBuf = 0;
330 SecurityContainer.pSecurity = NULL;
331
332 if ( Level != 2 )
333 {
334 FIXME( "Unsupported level %d\n", Level );
336 return hHandle;
337 }
338 else
339 {
340 PPRINTER_INFO_2W pi2w = (PPRINTER_INFO_2W)pPrinter;
341 if ( pi2w )
342 {
343 if ( pi2w->pDevMode )
344 {
345 if ( IsValidDevmodeNoSizeW( pi2w->pDevMode ) )
346 {
347 DevModeContainer.cbBuf = pi2w->pDevMode->dmSize + pi2w->pDevMode->dmDriverExtra;
348 DevModeContainer.pDevMode = (PBYTE)pi2w->pDevMode;
349 }
350 }
351
352 if ( pi2w->pSecurityDescriptor )
353 {
354 sd = get_sd( pi2w->pSecurityDescriptor, &size );
355 if ( sd )
356 {
357 SecurityContainer.cbBuf = size;
358 SecurityContainer.pSecurity = (PBYTE)sd;
359 }
360 }
361 }
362 else
363 {
365 return hHandle;
366 }
367 }
368
369 PrinterContainer.PrinterInfo.pPrinterInfo1 = (WINSPOOL_PRINTER_INFO_1*)pPrinter;
370 PrinterContainer.Level = Level;
371
372 // Do the RPC call
374 {
375 dwErrorCode = _RpcAddPrinter( pName, &PrinterContainer, &DevModeContainer, &SecurityContainer, &hPrinter );
376 }
378 {
379 dwErrorCode = RpcExceptionCode();
380 }
382
383 if (hPrinter)
384 {
385 // Create a new SPOOLER_HANDLE structure.
387 if (!pHandle)
388 {
389 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
390 ERR("HeapAlloc failed!\n");
391 _RpcDeletePrinter(hPrinter);
392 _RpcClosePrinter(hPrinter);
393 goto Cleanup;
394 }
395
396 pHandle->Sig = SPOOLER_HANDLE_SIG;
397 pHandle->hPrinter = hPrinter;
400 hHandle = (HANDLE)pHandle;
401 }
402
403Cleanup:
404 if ( sd ) HeapFree( GetProcessHeap(), 0, sd );
405
406 SetLastError(dwErrorCode);
407 return hHandle;
408}
#define FIXME(fmt,...)
Definition: precomp.h:53
DWORD _RpcAddPrinter(WINSPOOL_HANDLE pName, WINSPOOL_PRINTER_CONTAINER *pPrinterContainer, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, WINSPOOL_SECURITY_CONTAINER *pSecurityContainer, WINSPOOL_PRINTER_HANDLE *pHandle)
Definition: printers.c:31
DWORD _RpcClosePrinter(WINSPOOL_PRINTER_HANDLE *phPrinter)
Definition: printers.c:45
DWORD _RpcDeletePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:66
BOOL WINAPI IsValidDevmodeNoSizeW(PDEVMODEW pDevmode)
Definition: devmode.c:238
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
static HRESULT get_sd(SECURITY_DESCRIPTOR **sd, DWORD *size)
Definition: security.c:61
GLsizeiptr size
Definition: glext.h:5919
static const WCHAR sd[]
Definition: suminfo.c:286
PSECURITY_DESCRIPTOR pSecurityDescriptor
Definition: winspool.h:74
HANDLE hSpoolFileHandle
Definition: precomp.h:53
DWORD_PTR Sig
Definition: precomp.h:40
union _WINSPOOL_PRINTER_CONTAINER::@3442 PrinterInfo
WINSPOOL_PRINTER_INFO_1 * pPrinterInfo1
Definition: winspool.idl:698
WORD dmDriverExtra
Definition: wingdi.h:1621
WORD dmSize
Definition: wingdi.h:1620
PVOID HANDLE
Definition: typedefs.h:73
#define SPOOLER_HANDLE_SIG
Definition: precomp.h:32
struct _PRINTER_INFO_2W * PPRINTER_INFO_2W

◆ CallCommonPropertySheetUI()

LONG WINAPI CallCommonPropertySheetUI ( HWND  hWnd,
PFNPROPSHEETUI  pfnPropSheetUI,
LPARAM  lparam,
LPDWORD  pResult 
)

Definition at line 1155 of file printers.c.

1156{
1159
1160 FIXME("CallCommonPropertySheetUI(%p, %p, 0x%lx, %p)\n", hWnd, pfnPropSheetUI, lparam, pResult);
1161
1162 if ( ( hLibrary = LoadLibraryA( "compstui.dll" ) ) )
1163 {
1164 fpCommonPropertySheetUIW = (PVOID) GetProcAddress(hLibrary, "CommonPropertySheetUIW");
1165
1167 {
1168 Ret = fpCommonPropertySheetUIW( hWnd, pfnPropSheetUI, lparam, pResult );
1169 }
1170
1172 }
1173 return Ret;
1174}
@ lparam
Definition: SystemMenu.c:31
HWND hWnd
Definition: settings.c:17
static COMMONPROPERTYSHEETUIW fpCommonPropertySheetUIW
Definition: printers.c:27
HMODULE hLibrary
Definition: odbccp32.c:12
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
long LONG
Definition: pedump.c:60
#define ERR_CPSUI_GETLASTERROR
Definition: compstui.h:644
void * PVOID
Definition: typedefs.h:50

Referenced by DocumentPropertiesW(), and PrinterProperties().

◆ ClosePrinter()

BOOL WINAPI ClosePrinter ( HANDLE  hPrinter)

Definition at line 411 of file printers.c.

412{
413 DWORD dwErrorCode;
414 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
415
416 TRACE("ClosePrinter(%p)\n", hPrinter);
417
418 // Sanity checks.
419 if ( IntProtectHandle( hPrinter, TRUE ) )
420 {
421 dwErrorCode = ERROR_INVALID_HANDLE;
422 goto Cleanup;
423 }
424
425 // Do the RPC call.
427 {
428 dwErrorCode = _RpcClosePrinter(&pHandle->hPrinter);
429 }
431 {
432 dwErrorCode = RpcExceptionCode();
433 ERR("_RpcClosePrinter failed with exception code %lu!\n", dwErrorCode);
434 }
436
437 // Close any open file handle.
438 if (pHandle->hSPLFile != INVALID_HANDLE_VALUE)
439 CloseHandle(pHandle->hSPLFile);
440
441 pHandle->Sig = -1;
442
443 // Free the memory for the handle.
444 HeapFree(hProcessHeap, 0, pHandle);
445
446Cleanup:
447 SetLastError(dwErrorCode);
448 return (dwErrorCode == ERROR_SUCCESS);
449}
#define TRUE
Definition: types.h:120
LONG WINAPI IntProtectHandle(HANDLE, BOOL)
Definition: utils.c:107

Referenced by AdvancedSetupDialog(), GetMonitorUI(), LocalmonClosePort(), LocalmonEndDocPort(), localui_AddPortUI(), localui_ConfigurePortUI(), localui_DeletePortUI(), pagesetup_change_printer(), pagesetup_printer_properties(), PRINTDLG_ChangePrinterA(), PRINTDLG_ChangePrinterW(), PRINTDLG_WMCommandA(), PRINTDLG_WMCommandW(), PrintDlgA(), PrintDlgExA(), PrintDlgExW(), PrintDlgW(), PrintRawJob(), START_TEST(), test_ClosePrinter(), test_DocumentProperties(), test_EnumForms(), test_GetPrinter(), test_GetPrinterData(), test_GetPrinterDataEx(), test_GetPrinterDriver(), test_OpenPrinter(), test_OpenPrinter_defaults(), test_XcvDataW_MonitorUI(), test_XcvDataW_PortIsValid(), and wmain().

◆ ConstructPrinterFriendlyName()

LONG WINAPI ConstructPrinterFriendlyName ( PWSTR  ,
PVOID  ,
LPDWORD  Size 
)

◆ CreatePrinterFriendlyName()

LONG WINAPI CreatePrinterFriendlyName ( PCOMPUI_USERDATA  pcui_ud,
LPWSTR  pszPrinterName 
)

Definition at line 875 of file printers.c.

876{
877 LONG Result = 0;
878 DWORD Size = 0;
880
881 hLibrary = LoadLibraryA( "printui.dll" );
882
883 if ( hLibrary )
884 {
885 fpConstructPrinterFriendlyName = (PVOID)GetProcAddress( hLibrary, "ConstructPrinterFriendlyName" );
886
888 {
889 if ( !fpConstructPrinterFriendlyName( pszPrinterName, NULL, &Size ) )
890 {
892 {
893 PWSTR pwstr = DllAllocSplMem( (Size + 1) * sizeof(WCHAR) );
894
895 pcui_ud->pszPrinterName = pwstr;
896
897 if ( pwstr )
898 Result = fpConstructPrinterFriendlyName( pszPrinterName, pwstr, &Size );
899 }
900 }
901 }
903 }
904
905 if ( !Result )
906 {
907 DllFreeSplMem( pcui_ud->pszPrinterName );
908 pcui_ud->pszPrinterName = AllocSplStr( pszPrinterName );
909 }
910
911 return Result;
912}
static CONSTRUCTPRINTERFRIENDLYNAME fpConstructPrinterFriendlyName
Definition: printers.c:46
LPWSTR pszPrinterName
Definition: printers.c:54
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
PWSTR WINAPI AllocSplStr(PCWSTR pwszInput)
Definition: memory.c:56
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DevicePropertySheets(), and DocumentPropertySheets().

◆ CreateUIUserData()

BOOL FASTCALL CreateUIUserData ( ULONG_PTR puserdata,
HANDLE  hPrinter 
)

Definition at line 774 of file printers.c.

775{
777
778 *puserdata = (ULONG_PTR)pcui_ud;
779 FIXME("CreateUIUserData\n");
780 if ( pcui_ud )
781 {
782 pcui_ud->hModule = LoadPrinterDriver( hPrinter );
783
784 if ( !pcui_ud->hModule )
785 {
786 DllFreeSplMem( pcui_ud );
787 *puserdata = 0;
788 }
789 }
790 return *puserdata != 0;
791}
HMODULE WINAPI LoadPrinterDriver(HANDLE hspool)
Definition: printers.c:488
#define ULONG_PTR
Definition: config.h:101
HMODULE hModule
Definition: printers.c:53

Referenced by DevicePropertySheets(), and DocumentPropertySheets().

◆ DeletePrinter()

BOOL WINAPI DeletePrinter ( HANDLE  hPrinter)

Definition at line 452 of file printers.c.

453{
454 DWORD dwErrorCode;
455 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
456
457 TRACE("DeletePrinter(%p)\n", hPrinter);
458
459 // Sanity checks.
460 if (!pHandle)
461 {
462 dwErrorCode = ERROR_INVALID_HANDLE;
463 goto Cleanup;
464 }
465
466 // Do the RPC call.
468 {
469 dwErrorCode = _RpcDeletePrinter(&pHandle->hPrinter);
470 }
472 {
473 dwErrorCode = RpcExceptionCode();
474 ERR("_RpcDeletePrinter failed with exception code %lu!\n", dwErrorCode);
475 }
477
478Cleanup:
479 SetLastError(dwErrorCode);
480 return (dwErrorCode == ERROR_SUCCESS);
481}

◆ DestroyUIUserData()

VOID FASTCALL DestroyUIUserData ( ULONG_PTR puserdata)

Definition at line 795 of file printers.c.

796{
797 PCOMPUI_USERDATA pcui_ud = (PCOMPUI_USERDATA)*puserdata;
798 FIXME("DestroyUIUserData\n");
799 if ( pcui_ud )
800 {
801 if ( pcui_ud->hModule )
802 {
803 FreeLibrary( pcui_ud->hModule );
804 pcui_ud->hModule = NULL;
805 }
806
807 if ( pcui_ud->pszPrinterName )
808 {
809 DllFreeSplMem( pcui_ud->pszPrinterName );
810 pcui_ud->pszPrinterName = NULL;
811 }
812
813 DllFreeSplMem( pcui_ud );
814 *puserdata = 0;
815 }
816}
struct _COMPUI_USERDATA * PCOMPUI_USERDATA

Referenced by DevicePropertySheets(), and DocumentPropertySheets().

◆ DeviceCapabilitiesA()

DWORD WINAPI DeviceCapabilitiesA ( LPCSTR  pDevice,
LPCSTR  pPort,
WORD  fwCapability,
LPSTR  pOutput,
const DEVMODEA pDevMode 
)

Definition at line 529 of file printers.c.

530{
532 PDEVMODEW pdmwInput = NULL;
533 BOOL bReturnValue = GDI_ERROR;
534 DWORD cch;
535
536 FIXME("DeviceCapabilitiesA(%s, %s, %hu, %p, %p)\n", pDevice, pPort, fwCapability, pOutput, pDevMode);
537
538 if (pDevice)
539 {
540 // Convert pName to a Unicode string pwszDeviceName.
541 cch = strlen(pDevice);
542
543 pwszDeviceName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
544 if (!pwszDeviceName)
545 {
547 ERR("HeapAlloc failed!\n");
548 goto Cleanup;
549 }
550
552 }
553
554 if (pDevMode)
555 {
557 }
558
559 // pPort is ignored so no need to pass it.
560 bReturnValue = DeviceCapabilitiesW( pwszDeviceName, NULL, fwCapability, (LPWSTR)pOutput, (const DEVMODEW*) pdmwInput );
561
562Cleanup:
565
566 if (pdmwInput)
567 HeapFree(hProcessHeap, 0, pdmwInput);
568
569 return bReturnValue;
570}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
DWORD WINAPI DeviceCapabilitiesW(LPCWSTR pDevice, LPCWSTR pPort, WORD fwCapability, LPWSTR pOutput, const DEVMODEW *pDevMode)
Definition: printers.c:573
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
unsigned int BOOL
Definition: ntddk_ex.h:94
FxDevice * pDevice
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR pwszDeviceName
Definition: winddi.h:3556
#define GDI_ERROR
Definition: wingdi.h:1309
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ DeviceCapabilitiesW()

DWORD WINAPI DeviceCapabilitiesW ( LPCWSTR  pDevice,
LPCWSTR  pPort,
WORD  fwCapability,
LPWSTR  pOutput,
const DEVMODEW pDevMode 
)

Definition at line 573 of file printers.c.

574{
575 HANDLE hPrinter;
577 DWORD iDevCap = GDI_ERROR;
578
579 FIXME("DeviceCapabilitiesW(%S, %S, %hu, %p, %p)\n", pDevice, pPort, fwCapability, pOutput, pDevMode);
580
581 if ( pDevMode )
582 {
583 if (!IsValidDevmodeNoSizeW( (PDEVMODEW)pDevMode ) )
584 {
585 ERR("DeviceCapabilitiesW : Devode Invalid\n");
586 return -1;
587 }
588 }
589
590 if ( OpenPrinterW( (LPWSTR)pDevice, &hPrinter, NULL ) )
591 {
592 hLibrary = LoadPrinterDriver( hPrinter );
593
594 if ( hLibrary )
595 {
596 fpDeviceCapabilities = (PVOID)GetProcAddress( hLibrary, "DrvDeviceCapabilities" );
597
599 {
600 iDevCap = fpDeviceCapabilities( hPrinter, (PWSTR)pDevice, fwCapability, pOutput, (PDEVMODE)pDevMode );
601 }
602
604 }
605
606 ClosePrinter( hPrinter );
607 }
608
609 return iDevCap;
610}
static DEVICECAPABILITIES fpDeviceCapabilities
Definition: printers.c:19
WINBOOL WINAPI OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault)
Definition: printers.c:2653
WINBOOL WINAPI ClosePrinter(HANDLE hPrinter)
Definition: printers.c:176

Referenced by DeviceCapabilitiesA().

◆ DevicePropertySheets()

LONG WINAPI DevicePropertySheets ( PPROPSHEETUI_INFO  pCPSUIInfo,
LPARAM  lparam 
)

Definition at line 1069 of file printers.c.

1070{
1071 LONG Result = 0;
1072 PDEVICEPROPERTYHEADER pdphdr;
1073
1074 FIXME("DevicePropertySheets(%p, 0x%lx)\n", pCPSUIInfo, lparam);
1075
1076 if ( pCPSUIInfo )
1077 {
1078 PSETRESULT_INFO psri;
1079 PPROPSHEETUI_INFO_HEADER ppsuiihdr;
1080 PCOMPUI_USERDATA pcui_ud;
1081 pdphdr = (PDEVICEPROPERTYHEADER)pCPSUIInfo->lParamInit;
1082
1083 if ( pdphdr->cbSize < sizeof(DEVICEPROPERTYHEADER) )
1084 {
1086 return Result;
1087 }
1088
1089 switch ( pCPSUIInfo->Reason )
1090 {
1092 {
1093 FIXME("DevPS : PROPSHEETUI_REASON_INIT\n");
1094 if ( CreateUIUserData( &pCPSUIInfo->UserData, pdphdr->hPrinter ) )
1095 {
1096 pcui_ud = (PCOMPUI_USERDATA)pCPSUIInfo->UserData;
1097
1098 fpDevicePropertySheets = (PVOID)GetProcAddress( pcui_ud->hModule, "DrvDevicePropertySheets" );
1099
1101 {
1102 pCPSUIInfo->pfnComPropSheet( pCPSUIInfo->hComPropSheet,
1104 -3, // What type of handle is this?
1105 0 ); // Not used, must be zero.
1106
1107 Result = pCPSUIInfo->pfnComPropSheet( pCPSUIInfo->hComPropSheet,
1110 pCPSUIInfo->lParamInit );
1111 break;
1112 }
1113 FIXME("DevPS : PROPSHEETUI_REASON_INIT Fail\n");
1114 DestroyUIUserData( &pCPSUIInfo->UserData );
1115 }
1116 }
1117 break;
1118
1120 FIXME("DevPS : PROPSHEETUI_REASON_GET_INFO_HEADER\n");
1121
1122 ppsuiihdr = (PPROPSHEETUI_INFO_HEADER)lparam;
1123
1124 pcui_ud = (PCOMPUI_USERDATA)pCPSUIInfo->UserData;
1125
1126 CreatePrinterFriendlyName( pcui_ud, pdphdr->pszPrinterName );
1127
1129 ppsuiihdr->pTitle = pcui_ud->pszPrinterName;
1130 ppsuiihdr->hInst = hinstWinSpool;
1131 ppsuiihdr->IconID = IDI_CPSUI_DOCUMENT;
1132
1133 Result = CPSUI_OK;
1134 break;
1135
1137 FIXME("DevPS : PROPSHEETUI_REASON_DESTROY\n");
1138 DestroyUIUserData( &pCPSUIInfo->UserData );
1139 Result = CPSUI_OK;
1140 break;
1141
1143 FIXME("DevPS : PROPSHEETUI_REASON_SET_RESULT\n");
1144 psri = (PSETRESULT_INFO)lparam;
1145 pCPSUIInfo->Result = psri->Result;
1146 Result = CPSUI_OK;
1147 break;
1148 }
1149 }
1150 return Result;
1151}
static DEVICEPROPERTYSHEETS fpDevicePropertySheets
Definition: printers.c:22
LONG WINAPI CreatePrinterFriendlyName(PCOMPUI_USERDATA pcui_ud, LPWSTR pszPrinterName)
Definition: printers.c:875
HINSTANCE hinstWinSpool
Definition: main.c:12
BOOL FASTCALL CreateUIUserData(ULONG_PTR *puserdata, HANDLE hPrinter)
Definition: printers.c:774
VOID FASTCALL DestroyUIUserData(ULONG_PTR *puserdata)
Definition: printers.c:795
if(dx< 0)
Definition: linetemp.h:194
struct _SETRESULT_INFO * PSETRESULT_INFO
#define PROPSHEETUI_REASON_INIT
Definition: compstui.h:627
#define PSUIHDRF_PROPTITLE
Definition: compstui.h:693
struct _PROPSHEETUI_INFO_HEADER * PPROPSHEETUI_INFO_HEADER
#define CPSFUNC_SET_FUSION_CONTEXT
Definition: compstui.h:575
#define IDI_CPSUI_DOCUMENT
Definition: compstui.h:88
#define PROPSHEETUI_REASON_DESTROY
Definition: compstui.h:629
#define CPSFUNC_ADD_PFNPROPSHEETUIW
Definition: compstui.h:552
#define PROPSHEETUI_REASON_SET_RESULT
Definition: compstui.h:630
#define PSUIHDRF_NOAPPLYNOW
Definition: compstui.h:692
#define CPSUI_OK
Definition: compstui.h:640
#define PROPSHEETUI_REASON_GET_INFO_HEADER
Definition: compstui.h:628
struct _DEVICEPROPERTYHEADER * PDEVICEPROPERTYHEADER
HANDLE hComPropSheet
Definition: compstui.h:889
PFNCOMPROPSHEET pfnComPropSheet
Definition: compstui.h:890
ULONG_PTR UserData
Definition: compstui.h:892
LPARAM lParamInit
Definition: compstui.h:891
ULONG_PTR Result
Definition: compstui.h:893
LRESULT Result
Definition: compstui.h:849
LONG_PTR LPARAM
Definition: windef.h:208

Referenced by PrinterProperties().

◆ DevQueryPrint()

BOOL WINAPI DevQueryPrint ( HANDLE  hPrinter,
LPDEVMODEW  pDevMode,
DWORD pResID 
)

Definition at line 614 of file printers.c.

615{
617 BOOL Ret = FALSE;
618
619 hLibrary = LoadPrinterDriver( hPrinter );
620
621 if ( hLibrary )
622 {
623 fpDevQueryPrint = (PVOID)GetProcAddress( hLibrary, "DevQueryPrint" );
624
625 if ( fpDevQueryPrint )
626 {
627 Ret = fpDevQueryPrint( hPrinter, pDevMode, pResID );
628 }
629
631 }
632 return Ret;
633}
static DEVQUERYPRINT fpDevQueryPrint
Definition: printers.c:36

◆ DevQueryPrintEx()

BOOL WINAPI DevQueryPrintEx ( PDEVQUERYPRINT_INFO  pDQPInfo)

Definition at line 636 of file printers.c.

637{
639 BOOL Ret = FALSE;
640
641 hLibrary = LoadPrinterDriver( pDQPInfo->hPrinter );
642
643 if ( hLibrary )
644 {
645 fpDevQueryPrintEx = (PVOID)GetProcAddress( hLibrary, "DevQueryPrintEx" );
646
647 if ( fpDevQueryPrintEx )
648 {
649 Ret = fpDevQueryPrintEx( pDQPInfo );
650 }
651
653 }
654 return Ret;
655}
static DEVQUERYPRINTEX fpDevQueryPrintEx
Definition: printers.c:39

◆ DocumentEvent()

INT WINAPI DocumentEvent ( HANDLE  hPrinter,
HDC  hdc,
int  iEsc,
ULONG  cbIn,
PVOID  pvIn,
ULONG  cbOut,
PVOID  pvOut 
)

Definition at line 658 of file printers.c.

659{
660 FIXME("DocumentEvent(%p, %p, %lu, %lu, %p, %lu, %p)\n", hPrinter, hdc, iEsc, cbIn, pvIn, cbOut, pvOut);
663}
#define UNIMPLEMENTED
Definition: debug.h:118
HDC hdc
Definition: main.c:9
#define DOCUMENTEVENT_UNSUPPORTED
Definition: winddiui.h:90
_In_ ULONG iEsc
Definition: winddi.h:3529

◆ DocumentPropertiesA()

LONG WINAPI DocumentPropertiesA ( HWND  hWnd,
HANDLE  hPrinter,
LPSTR  pDeviceName,
PDEVMODEA  pDevModeOutput,
PDEVMODEA  pDevModeInput,
DWORD  fMode 
)

Definition at line 666 of file printers.c.

667{
669 PDEVMODEW pdmwInput = NULL;
670 PDEVMODEW pdmwOutput = NULL;
671 LONG lReturnValue = -1;
672 DWORD cch;
673
674 FIXME("DocumentPropertiesA(%p, %p, %s, %p, %p, %lu)\n", hWnd, hPrinter, pDeviceName, pDevModeOutput, pDevModeInput, fMode);
675
676 if (pDeviceName)
677 {
678 // Convert pName to a Unicode string pwszDeviceName.
679 cch = strlen(pDeviceName);
680
681 pwszDeviceName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
682 if (!pwszDeviceName)
683 {
685 ERR("HeapAlloc failed!\n");
686 goto Cleanup;
687 }
688
689 MultiByteToWideChar(CP_ACP, 0, pDeviceName, -1, pwszDeviceName, cch + 1);
690 }
691
692 if (pDevModeInput)
693 {
694 // Create working buffer for input to DocumentPropertiesW.
695 RosConvertAnsiDevModeToUnicodeDevmode(pDevModeInput, &pdmwInput);
696 }
697
698 if (pDevModeOutput)
699 {
700 // Create working buffer for output from DocumentPropertiesW.
701
702 // Do it RIGHT! Get the F...ing Size!
704
705 if ( Size < 0 )
706 {
707 goto Cleanup;
708 }
709
710 pdmwOutput = HeapAlloc(hProcessHeap, 0, Size);
711 if (!pdmwOutput)
712 {
714 ERR("HeapAlloc failed!\n");
715 goto Cleanup;
716 }
717 }
718
719 lReturnValue = DocumentPropertiesW(hWnd, hPrinter, pwszDeviceName, pdmwOutput, pdmwInput, fMode);
720 FIXME("lReturnValue from DocumentPropertiesW is '%ld'.\n", lReturnValue);
721
722 if (lReturnValue < 0)
723 {
724 FIXME("DocumentPropertiesW failed!\n");
725 goto Cleanup;
726 }
727
728 if (pdmwOutput)
729 {
730 RosConvertUnicodeDevModeToAnsiDevmode(pdmwOutput, pDevModeOutput);
731 }
732
733Cleanup:
736
737 if (pdmwInput)
738 HeapFree(hProcessHeap, 0, pdmwInput);
739
740 if (pdmwOutput)
741 HeapFree(hProcessHeap, 0, pdmwOutput);
742
743 return lReturnValue;
744}
LONG WINAPI DocumentPropertiesW(HWND hWnd, HANDLE hPrinter, LPWSTR pDeviceName, PDEVMODEW pDevModeOutput, PDEVMODEW pDevModeInput, DWORD fMode)
Definition: printers.c:1177
void RosConvertUnicodeDevModeToAnsiDevmode(PDEVMODEW pDevModeInput, PDEVMODEA pDevModeOutput)
Definition: devmode.c:353

Referenced by PRINTDLG_ChangePrinterA(), PRINTDLG_WMCommandA(), and test_DocumentProperties().

◆ DocumentPropertiesW()

LONG WINAPI DocumentPropertiesW ( HWND  hWnd,
HANDLE  hPrinter,
LPWSTR  pDeviceName,
PDEVMODEW  pDevModeOutput,
PDEVMODEW  pDevModeInput,
DWORD  fMode 
)

Definition at line 1177 of file printers.c.

1178{
1179 HANDLE hUseHandle = NULL;
1180 DOCUMENTPROPERTYHEADER docprophdr;
1181 LONG Result = IDOK;
1182
1183 FIXME("DocumentPropertiesW(%p, %p, %S, %p, %p, %lu)\n", hWnd, hPrinter, pDeviceName, pDevModeOutput, pDevModeInput, fMode);
1184
1185 if (hPrinter)
1186 {
1187 hUseHandle = hPrinter;
1188 }
1189 else if (!OpenPrinterW(pDeviceName, &hUseHandle, NULL))
1190 {
1191 ERR("No handle, and no usable printer name passed in\n");
1192 return -1;
1193 }
1194
1195 if ( !(fMode & DM_IN_BUFFER ) ||
1196 ( ( pDevModeInput && !IsValidDevmodeNoSizeW( (PDEVMODEW)pDevModeInput ) ) ) )
1197 {
1198 pDevModeInput = NULL;
1199 fMode &= ~DM_IN_BUFFER;
1200 }
1201
1202 docprophdr.cbSize = sizeof(DOCUMENTPROPERTYHEADER);
1203 docprophdr.Reserved = 0;
1204 docprophdr.hPrinter = hUseHandle;
1205 docprophdr.pszPrinterName = pDeviceName;
1206 docprophdr.cbOut = 0;
1207
1208 if ( pDevModeOutput )
1209 {
1210 docprophdr.pdmIn = NULL;
1211 docprophdr.pdmOut = NULL;
1212 docprophdr.fMode = 0;
1213 FIXME("DPW : Call DocumentPropertySheets with pDevModeOutput %p\n",pDevModeOutput);
1214 docprophdr.cbOut = DocumentPropertySheets( NULL, (LPARAM)&docprophdr );
1215 }
1216
1217 docprophdr.pdmIn = pDevModeInput;
1218 docprophdr.pdmOut = pDevModeOutput;
1219 docprophdr.fMode = fMode;
1220
1221 if ( fMode & DM_IN_PROMPT )
1222 {
1224
1225 //
1226 // Now call the Property Sheet for Print > Properties.
1227 //
1229 {
1230 FIXME("CallCommonPropertySheetUI return error\n");
1232 }
1233 else
1234 Result = (Result == CPSUI_OK) ? IDOK : IDCANCEL;
1235 FIXME("CallCommonPropertySheetUI returned\n");
1236 }
1237 else
1238 {
1239 FIXME("DPW : CallDocumentPropertySheets\n");
1240 Result = DocumentPropertySheets( NULL, (LPARAM)&docprophdr );
1241 }
1242
1244 {
1245 if ( pDevModeOutput )
1246 {
1247 if ( !IsValidDevmodeNoSizeW( pDevModeOutput ) )
1248 {
1249 ERR("DPW : Improper pDevModeOutput size.\n");
1250 Result = -1;
1251 }
1252 }
1253 else
1254 {
1255 ERR("No pDevModeOutput\n");
1256 }
1257 }
1258
1259 if (hUseHandle && !hPrinter)
1260 ClosePrinter(hUseHandle);
1261 return Result;
1262}
LONG WINAPI DocumentPropertySheets(PPROPSHEETUI_INFO pCPSUIInfo, LPARAM lparam)
Definition: printers.c:919
LONG WINAPI CallCommonPropertySheetUI(HWND hWnd, PFNPROPSHEETUI pfnPropSheetUI, LPARAM lparam, LPDWORD pResult)
Definition: printers.c:1155
#define CPSUI_CANCEL
Definition: compstui.h:639
#define ERR_CPSUI_ALLOCMEM_FAILED
Definition: compstui.h:645
LONG(FAR * PFNPROPSHEETUI)(PPROPSHEETUI_INFO pPSUIInfo, LPARAM lParam)
Definition: compstui.h:905
struct _DOCUMENTPROPERTYHEADER DOCUMENTPROPERTYHEADER
uint32_t * LPDWORD
Definition: typedefs.h:59
#define DM_IN_BUFFER
Definition: windef.h:357
#define DM_IN_PROMPT
Definition: windef.h:358
#define IDCANCEL
Definition: winuser.h:831
#define IDOK
Definition: winuser.h:830

Referenced by DocumentPropertiesA(), pagesetup_change_printer(), pagesetup_printer_properties(), PRINTDLG_ChangePrinterW(), and PRINTDLG_WMCommandW().

◆ DocumentPropertySheets()

LONG WINAPI DocumentPropertySheets ( PPROPSHEETUI_INFO  pCPSUIInfo,
LPARAM  lparam 
)

Definition at line 919 of file printers.c.

920{
921 LONG Result = -1;
923
924 FIXME("DocumentPropertySheets(%p, 0x%lx)\n", pCPSUIInfo, lparam);
925
926 // If pPSUIInfo is NULL, and if either lParam -> fMode is zero or lParam -> pdmOut is NULL,
927 // this function should return the size, in bytes, of the printer's DEVMODEW structure.
928 if ( !pCPSUIInfo && lparam )
929 {
931
932 if ( pdphdr->cbSize >= sizeof(PDOCUMENTPROPERTYHEADER) &&
933 !(pdphdr->fMode & DM_PROMPT) )
934 {
936
937 if ( hLibrary )
938 {
939 fpDocumentPropertySheets = (PVOID)GetProcAddress( hLibrary, "DrvDocumentPropertySheets" );
940
942 {
943 FIXME("DPS : fpDocumentPropertySheets(%p, 0x%lx) pdmOut %p\n", pCPSUIInfo, lparam, pdphdr->pdmOut);
944 Result = fpDocumentPropertySheets( pCPSUIInfo, lparam );
945 FIXME("DPS : fpDocumentPropertySheets result %d cbOut %d\n",Result, pdphdr->cbOut);
946 }
947 else
948 {
949 //
950 // ReactOS backup!!! Currently no supporting UI driver.
951 //
952 PRINTER_INFO_9W * pi9 = get_devmodeW( pdphdr->hPrinter );
953 if ( pi9 )
954 {
956 FIXME("IDPS : Using ReactOS backup!!! DevMode Size %d\n",Result);
957 HeapFree(hProcessHeap, 0, pi9);
958 }
959 }
960
962
963 if ( Result > 0 )
964 {
965 IntFixUpDevModeNames( pdphdr );
966 }
967
968 return Result;
969 }
970 else
971 {
973 }
974 }
975 else
976 {
978 }
979 return Result;
980 }
981
982 Result = 0;
983
984 if ( pCPSUIInfo )
985 {
986 PSETRESULT_INFO psri;
987 PPROPSHEETUI_INFO_HEADER ppsuiihdr;
988 PCOMPUI_USERDATA pcui_ud;
989 pdphdr = (PDOCUMENTPROPERTYHEADER)pCPSUIInfo->lParamInit;
990
991 if ( pdphdr->cbSize < sizeof(PDOCUMENTPROPERTYHEADER) )
992 {
994 return Result;
995 }
996
997 switch ( pCPSUIInfo->Reason )
998 {
1000 {
1001 FIXME("DocPS : PROPSHEETUI_REASON_INIT\n");
1002 if ( CreateUIUserData( &pCPSUIInfo->UserData, pdphdr->hPrinter ) )
1003 {
1004 pcui_ud = (PCOMPUI_USERDATA)pCPSUIInfo->UserData;
1005
1006 fpDocumentPropertySheets = (PVOID)GetProcAddress( pcui_ud->hModule, "DrvDocumentPropertySheets" );
1007
1009 {
1010 pCPSUIInfo->pfnComPropSheet( pCPSUIInfo->hComPropSheet,
1012 -3, // What type of handle is this?
1013 0 ); // Not used, must be zero.
1014
1015 Result = pCPSUIInfo->pfnComPropSheet( pCPSUIInfo->hComPropSheet,
1018 pCPSUIInfo->lParamInit );
1019 break;
1020 }
1021 FIXME("DocPS : PROPSHEETUI_REASON_INIT Fail\n");
1022 DestroyUIUserData( &pCPSUIInfo->UserData );
1023 }
1024 }
1025 break;
1026
1028 FIXME("DocPS : PROPSHEETUI_REASON_GET_INFO_HEADER\n");
1029
1030 ppsuiihdr = (PPROPSHEETUI_INFO_HEADER)lparam;
1031
1032 pcui_ud = (PCOMPUI_USERDATA)pCPSUIInfo->UserData;
1033
1034 CreatePrinterFriendlyName( pcui_ud, pdphdr->pszPrinterName );
1035
1037 ppsuiihdr->pTitle = pcui_ud->pszPrinterName;
1038 ppsuiihdr->hInst = hinstWinSpool;
1039 ppsuiihdr->IconID = IDI_CPSUI_DOCUMENT;
1040
1041 Result = CPSUI_OK;
1042 break;
1043
1045 FIXME("DocPS : PROPSHEETUI_REASON_DESTROY\n");
1046 DestroyUIUserData( &pCPSUIInfo->UserData );
1047 Result = CPSUI_OK;
1048 break;
1049
1051 FIXME("DocPS : PROPSHEETUI_REASON_SET_RESULT\n");
1052
1053 psri = (PSETRESULT_INFO)lparam;
1054
1055 pCPSUIInfo->Result = psri->Result;
1056 if ( pCPSUIInfo->Result > 0 )
1057 {
1058 IntFixUpDevModeNames( pdphdr );
1059 }
1060 Result = CPSUI_OK;
1061 break;
1062 }
1063 }
1064 return Result;
1065}
BOOL FASTCALL IntFixUpDevModeNames(PDOCUMENTPROPERTYHEADER pdphdr)
Definition: printers.c:820
static DOCUMENTPROPERTYSHEETS fpDocumentPropertySheets
Definition: printers.c:24
PRINTER_INFO_9W * get_devmodeW(HANDLE hprn)
Definition: printers.c:746
struct _DOCUMENTPROPERTYHEADER * PDOCUMENTPROPERTYHEADER
LPDEVMODEW pDevMode
Definition: winspool.h:170
#define DM_PROMPT
Definition: windef.h:354

Referenced by DocumentPropertiesW().

◆ EndDocPrinter()

BOOL WINAPI EndDocPrinter ( HANDLE  hPrinter)

Definition at line 1320 of file printers.c.

1321{
1322 DWORD dwErrorCode;
1323 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
1324
1325 TRACE("EndDocPrinter(%p)\n", hPrinter);
1326
1327 // Sanity checks.
1328 if (!pHandle)
1329 {
1330 dwErrorCode = ERROR_INVALID_HANDLE;
1331 goto Cleanup;
1332 }
1333
1334 if (pHandle->hSPLFile != INVALID_HANDLE_VALUE)
1335 {
1336 // For spooled jobs, the document is finished by calling _RpcScheduleJob.
1338 {
1339 dwErrorCode = _RpcScheduleJob(pHandle->hPrinter, pHandle->dwJobID);
1340 }
1342 {
1343 dwErrorCode = RpcExceptionCode();
1344 ERR("_RpcScheduleJob failed with exception code %lu!\n", dwErrorCode);
1345 }
1347
1348 // Close the spool file handle.
1349 CloseHandle(pHandle->hSPLFile);
1350 }
1351 else
1352 {
1353 // In all other cases, just call _RpcEndDocPrinter.
1355 {
1356 dwErrorCode = _RpcEndDocPrinter(pHandle->hPrinter);
1357 }
1359 {
1360 dwErrorCode = RpcExceptionCode();
1361 ERR("_RpcEndDocPrinter failed with exception code %lu!\n", dwErrorCode);
1362 }
1364 }
1365
1366 // A new document can now be started again.
1367 pHandle->bTrayIcon = pHandle->bJob = pHandle->bStartedDoc = FALSE;
1368
1369Cleanup:
1370 SetLastError(dwErrorCode);
1371 return (dwErrorCode == ERROR_SUCCESS);
1372}
DWORD _RpcScheduleJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId)
Definition: jobs.c:110
DWORD _RpcEndDocPrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:85

Referenced by PrintRawJob(), and wmain().

◆ EndPagePrinter()

BOOL WINAPI EndPagePrinter ( HANDLE  hPrinter)

Definition at line 1375 of file printers.c.

1376{
1377 DWORD dwErrorCode;
1378 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
1379
1380 TRACE("EndPagePrinter(%p)\n", hPrinter);
1381
1382 // Sanity checks.
1383 if (!pHandle)
1384 {
1385 dwErrorCode = ERROR_INVALID_HANDLE;
1386 goto Cleanup;
1387 }
1388
1389 if (pHandle->hSPLFile != INVALID_HANDLE_VALUE)
1390 {
1391 // For spooled jobs, we don't need to do anything.
1392 dwErrorCode = ERROR_SUCCESS;
1393 }
1394 else
1395 {
1396 // In all other cases, just call _RpcEndPagePrinter.
1398 {
1399 dwErrorCode = _RpcEndPagePrinter(pHandle->hPrinter);
1400 }
1402 {
1403 dwErrorCode = RpcExceptionCode();
1404 ERR("_RpcEndPagePrinter failed with exception code %lu!\n", dwErrorCode);
1405 }
1407 }
1408
1409Cleanup:
1410 SetLastError(dwErrorCode);
1411 return (dwErrorCode == ERROR_SUCCESS);
1412}
DWORD _RpcEndPagePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:104

Referenced by wmain().

◆ EnumPrintersA()

BOOL WINAPI EnumPrintersA ( DWORD  Flags,
PSTR  Name,
DWORD  Level,
PBYTE  pPrinterEnum,
DWORD  cbBuf,
PDWORD  pcbNeeded,
PDWORD  pcReturned 
)

Definition at line 1415 of file printers.c.

1416{
1417 DWORD dwErrorCode;
1418 DWORD cch;
1419 PWSTR pwszName = NULL;
1420 PSTR pszPrinterName = NULL;
1421 PSTR pszServerName = NULL;
1422 PSTR pszDescription = NULL;
1423 PSTR pszName = NULL;
1424 PSTR pszComment = NULL;
1425 PSTR pszShareName = NULL;
1426 PSTR pszPortName = NULL;
1427 PSTR pszDriverName = NULL;
1428 PSTR pszLocation = NULL;
1429 PSTR pszSepFile = NULL;
1430 PSTR pszPrintProcessor = NULL;
1431 PSTR pszDatatype = NULL;
1432 PSTR pszParameters = NULL;
1433 DWORD i;
1434 PPRINTER_INFO_1W ppi1w = NULL;
1435 PPRINTER_INFO_1A ppi1a = NULL;
1436 PPRINTER_INFO_2W ppi2w = NULL;
1437 PPRINTER_INFO_2A ppi2a = NULL;
1438 PPRINTER_INFO_4W ppi4w = NULL;
1439 PPRINTER_INFO_4A ppi4a = NULL;
1440 PPRINTER_INFO_5W ppi5w = NULL;
1441 PPRINTER_INFO_5A ppi5a = NULL;
1442
1443 TRACE("EnumPrintersA(%lu, %s, %lu, %p, %lu, %p, %p)\n", Flags, Name, Level, pPrinterEnum, cbBuf, pcbNeeded, pcReturned);
1444
1445 // Check for invalid levels here for early error return. MSDN says that only 1, 2, 4, and 5 are allowable.
1446 if (Level != 1 && Level != 2 && Level != 4 && Level != 5)
1447 {
1448 dwErrorCode = ERROR_INVALID_LEVEL;
1449 ERR("Invalid Level!\n");
1450 goto Cleanup;
1451 }
1452
1453 if (Name)
1454 {
1455 // Convert pName to a Unicode string pwszName.
1456 cch = strlen(Name);
1457
1458 pwszName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
1459 if (!pwszName)
1460 {
1461 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1462 ERR("HeapAlloc failed!\n");
1463 goto Cleanup;
1464 }
1465
1466 MultiByteToWideChar(CP_ACP, 0, Name, -1, pwszName, cch + 1);
1467 }
1468
1469 /* Ref: https://stackoverflow.com/questions/41147180/why-enumprintersa-and-enumprintersw-request-the-same-amount-of-memory */
1470 if (!EnumPrintersW(Flags, pwszName, Level, pPrinterEnum, cbBuf, pcbNeeded, pcReturned))
1471 {
1472 dwErrorCode = GetLastError();
1473 goto Cleanup;
1474 }
1475
1476 /* We are mapping multiple different pointers to the same pPrinterEnum pointer here so that */
1477 /* we can do in-place conversion. We read the Unicode response from the EnumPrintersW and */
1478 /* then we write back the ANSI conversion into the same buffer for our EnumPrintersA output */
1479
1480 /* mapping to pPrinterEnum for Unicode (w) characters for Levels 1, 2, 4, and 5 */
1481 ppi1w = (PPRINTER_INFO_1W)pPrinterEnum;
1482 ppi2w = (PPRINTER_INFO_2W)pPrinterEnum;
1483 ppi4w = (PPRINTER_INFO_4W)pPrinterEnum;
1484 ppi5w = (PPRINTER_INFO_5W)pPrinterEnum;
1485 /* mapping to pPrinterEnum for ANSI (a) characters for Levels 1, 2, 4, and 5 */
1486 ppi1a = (PPRINTER_INFO_1A)pPrinterEnum;
1487 ppi2a = (PPRINTER_INFO_2A)pPrinterEnum;
1488 ppi4a = (PPRINTER_INFO_4A)pPrinterEnum;
1489 ppi5a = (PPRINTER_INFO_5A)pPrinterEnum;
1490
1491 for (i = 0; i < *pcReturned; i++)
1492 {
1493 switch (Level)
1494 {
1495 case 1:
1496 {
1497 if (ppi1w[i].pDescription)
1498 {
1499 // Convert Unicode pDescription to a ANSI string pszDescription.
1500 cch = wcslen(ppi1w[i].pDescription);
1501
1502 pszDescription = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1503 if (!pszDescription)
1504 {
1505 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1506 ERR("HeapAlloc failed!\n");
1507 goto Cleanup;
1508 }
1509
1510 WideCharToMultiByte(CP_ACP, 0, ppi1w[i].pDescription, -1, pszDescription, cch + 1, NULL, NULL);
1511 StringCchCopyA(ppi1a[i].pDescription, cch + 1, pszDescription);
1512
1513 HeapFree(hProcessHeap, 0, pszDescription);
1514 }
1515
1516 if (ppi1w[i].pName)
1517 {
1518 // Convert Unicode pName to a ANSI string pszName.
1519 cch = wcslen(ppi1w[i].pName);
1520
1521 pszName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1522 if (!pszName)
1523 {
1524 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1525 ERR("HeapAlloc failed!\n");
1526 goto Cleanup;
1527 }
1528
1529 WideCharToMultiByte(CP_ACP, 0, ppi1w[i].pName, -1, pszName, cch + 1, NULL, NULL);
1530 StringCchCopyA(ppi1a[i].pName, cch + 1, pszName);
1531
1532 HeapFree(hProcessHeap, 0, pszName);
1533 }
1534
1535 if (ppi1w[i].pComment)
1536 {
1537 // Convert Unicode pComment to a ANSI string pszComment.
1538 cch = wcslen(ppi1w[i].pComment);
1539
1540 pszComment = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1541 if (!pszComment)
1542 {
1543 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1544 ERR("HeapAlloc failed!\n");
1545 goto Cleanup;
1546 }
1547
1548 WideCharToMultiByte(CP_ACP, 0, ppi1w[i].pComment, -1, pszComment, cch + 1, NULL, NULL);
1549 StringCchCopyA(ppi1a[i].pComment, cch + 1, pszComment);
1550
1551 HeapFree(hProcessHeap, 0, pszComment);
1552 }
1553 break;
1554 }
1555
1556
1557 case 2:
1558 {
1559 if (ppi2w[i].pServerName)
1560 {
1561 // Convert Unicode pServerName to a ANSI string pszServerName.
1562 cch = wcslen(ppi2w[i].pServerName);
1563
1564 pszServerName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1565 if (!pszServerName)
1566 {
1567 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1568 ERR("HeapAlloc failed!\n");
1569 goto Cleanup;
1570 }
1571
1572 WideCharToMultiByte(CP_ACP, 0, ppi2w[i].pServerName, -1, pszServerName, cch + 1, NULL, NULL);
1573 StringCchCopyA(ppi2a[i].pServerName, cch + 1, pszServerName);
1574
1575 HeapFree(hProcessHeap, 0, pszServerName);
1576 }
1577
1578 if (ppi2w[i].pPrinterName)
1579 {
1580 // Convert Unicode pPrinterName to a ANSI string pszPrinterName.
1581 cch = wcslen(ppi2w[i].pPrinterName);
1582
1583 pszPrinterName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1584 if (!pszPrinterName)
1585 {
1586 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1587 ERR("HeapAlloc failed!\n");
1588 goto Cleanup;
1589 }
1590
1591 WideCharToMultiByte(CP_ACP, 0, ppi2w[i].pPrinterName, -1, pszPrinterName, cch + 1, NULL, NULL);
1592 StringCchCopyA(ppi2a[i].pPrinterName, cch + 1, pszPrinterName);
1593
1594 HeapFree(hProcessHeap, 0, pszPrinterName);
1595 }
1596
1597 if (ppi2w[i].pShareName)
1598 {
1599 // Convert Unicode pShareName to a ANSI string pszShareName.
1600 cch = wcslen(ppi2w[i].pShareName);
1601
1602 pszShareName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1603 if (!pszShareName)
1604 {
1605 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1606 ERR("HeapAlloc failed!\n");
1607 goto Cleanup;
1608 }
1609
1610 WideCharToMultiByte(CP_ACP, 0, ppi2w[i].pShareName, -1, pszShareName, cch + 1, NULL, NULL);
1611 StringCchCopyA(ppi2a[i].pShareName, cch + 1, pszShareName);
1612
1613 HeapFree(hProcessHeap, 0, pszShareName);
1614 }
1615
1616 if (ppi2w[i].pPortName)
1617 {
1618 // Convert Unicode pPortName to a ANSI string pszPortName.
1619 cch = wcslen(ppi2w[i].pPortName);
1620
1621 pszPortName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1622 if (!pszPortName)
1623 {
1624 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1625 ERR("HeapAlloc failed!\n");
1626 goto Cleanup;
1627 }
1628
1629 WideCharToMultiByte(CP_ACP, 0, ppi2w[i].pPortName, -1, pszPortName, cch + 1, NULL, NULL);
1630 StringCchCopyA(ppi2a[i].pPortName, cch + 1, pszPortName);
1631
1632 HeapFree(hProcessHeap, 0, pszPortName);
1633 }
1634
1635 if (ppi2w[i].pDriverName)
1636 {
1637 // Convert Unicode pDriverName to a ANSI string pszDriverName.
1638 cch = wcslen(ppi2w[i].pDriverName);
1639
1640 pszDriverName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1641 if (!pszDriverName)
1642 {
1643 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1644 ERR("HeapAlloc failed!\n");
1645 goto Cleanup;
1646 }
1647
1648 WideCharToMultiByte(CP_ACP, 0, ppi2w[i].pDriverName, -1, pszDriverName, cch + 1, NULL, NULL);
1649 StringCchCopyA(ppi2a[i].pDriverName, cch + 1, pszDriverName);
1650
1651 HeapFree(hProcessHeap, 0, pszDriverName);
1652 }
1653
1654 if (ppi2w[i].pComment)
1655 {
1656 // Convert Unicode pComment to a ANSI string pszComment.
1657 cch = wcslen(ppi2w[i].pComment);
1658
1659 pszComment = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1660 if (!pszComment)
1661 {
1662 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1663 ERR("HeapAlloc failed!\n");
1664 goto Cleanup;
1665 }
1666
1667 WideCharToMultiByte(CP_ACP, 0, ppi2w[i].pComment, -1, pszComment, cch + 1, NULL, NULL);
1668 StringCchCopyA(ppi2a[i].pComment, cch + 1, pszComment);
1669
1670 HeapFree(hProcessHeap, 0, pszComment);
1671 }
1672
1673 if (ppi2w[i].pLocation)
1674 {
1675 // Convert Unicode pLocation to a ANSI string pszLocation.
1676 cch = wcslen(ppi2w[i].pLocation);
1677
1678 pszLocation = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1679 if (!pszLocation)
1680 {
1681 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1682 ERR("HeapAlloc failed!\n");
1683 goto Cleanup;
1684 }
1685
1686 WideCharToMultiByte(CP_ACP, 0, ppi2w[i].pLocation, -1, pszLocation, cch + 1, NULL, NULL);
1687 StringCchCopyA(ppi2a[i].pLocation, cch + 1, pszLocation);
1688
1689 HeapFree(hProcessHeap, 0, pszLocation);
1690 }
1691
1692
1693 if (ppi2w[i].pSepFile)
1694 {
1695 // Convert Unicode pSepFile to a ANSI string pszSepFile.
1696 cch = wcslen(ppi2w[i].pSepFile);
1697
1698 pszSepFile = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1699 if (!pszSepFile)
1700 {
1701 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1702 ERR("HeapAlloc failed!\n");
1703 goto Cleanup;
1704 }
1705
1706 WideCharToMultiByte(CP_ACP, 0, ppi2w[i].pSepFile, -1, pszSepFile, cch + 1, NULL, NULL);
1707 StringCchCopyA(ppi2a[i].pSepFile, cch + 1, pszSepFile);
1708
1709 HeapFree(hProcessHeap, 0, pszSepFile);
1710 }
1711
1712 if (ppi2w[i].pPrintProcessor)
1713 {
1714 // Convert Unicode pPrintProcessor to a ANSI string pszPrintProcessor.
1715 cch = wcslen(ppi2w[i].pPrintProcessor);
1716
1717 pszPrintProcessor = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1718 if (!pszPrintProcessor)
1719 {
1720 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1721 ERR("HeapAlloc failed!\n");
1722 goto Cleanup;
1723 }
1724
1725 WideCharToMultiByte(CP_ACP, 0, ppi2w[i].pPrintProcessor, -1, pszPrintProcessor, cch + 1, NULL, NULL);
1726 StringCchCopyA(ppi2a[i].pPrintProcessor, cch + 1, pszPrintProcessor);
1727
1728 HeapFree(hProcessHeap, 0, pszPrintProcessor);
1729 }
1730
1731
1732 if (ppi2w[i].pDatatype)
1733 {
1734 // Convert Unicode pDatatype to a ANSI string pszDatatype.
1735 cch = wcslen(ppi2w[i].pDatatype);
1736
1737 pszDatatype = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1738 if (!pszDatatype)
1739 {
1740 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1741 ERR("HeapAlloc failed!\n");
1742 goto Cleanup;
1743 }
1744
1745 WideCharToMultiByte(CP_ACP, 0, ppi2w[i].pDatatype, -1, pszDatatype, cch + 1, NULL, NULL);
1746 StringCchCopyA(ppi2a[i].pDatatype, cch + 1, pszDatatype);
1747
1748 HeapFree(hProcessHeap, 0, pszDatatype);
1749 }
1750
1751 if (ppi2w[i].pParameters)
1752 {
1753 // Convert Unicode pParameters to a ANSI string pszParameters.
1754 cch = wcslen(ppi2w[i].pParameters);
1755
1756 pszParameters = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1757 if (!pszParameters)
1758 {
1759 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1760 ERR("HeapAlloc failed!\n");
1761 goto Cleanup;
1762 }
1763
1764 WideCharToMultiByte(CP_ACP, 0, ppi2w[i].pParameters, -1, pszParameters, cch + 1, NULL, NULL);
1765 StringCchCopyA(ppi2a[i].pParameters, cch + 1, pszParameters);
1766
1767 HeapFree(hProcessHeap, 0, pszParameters);
1768 }
1769 if ( ppi2w[i].pDevMode )
1770 {
1771 RosConvertUnicodeDevModeToAnsiDevmode( ppi2w[i].pDevMode, ppi2a[i].pDevMode );
1772 }
1773 break;
1774 }
1775
1776 case 4:
1777 {
1778 if (ppi4w[i].pPrinterName)
1779 {
1780 // Convert Unicode pPrinterName to a ANSI string pszPrinterName.
1781 cch = wcslen(ppi4w[i].pPrinterName);
1782
1783 pszPrinterName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1784 if (!pszPrinterName)
1785 {
1786 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1787 ERR("HeapAlloc failed!\n");
1788 goto Cleanup;
1789 }
1790
1791 WideCharToMultiByte(CP_ACP, 0, ppi4w[i].pPrinterName, -1, pszPrinterName, cch + 1, NULL, NULL);
1792 StringCchCopyA(ppi4a[i].pPrinterName, cch + 1, pszPrinterName);
1793
1794 HeapFree(hProcessHeap, 0, pszPrinterName);
1795 }
1796
1797 if (ppi4w[i].pServerName)
1798 {
1799 // Convert Unicode pServerName to a ANSI string pszServerName.
1800 cch = wcslen(ppi4w[i].pServerName);
1801
1802 pszServerName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1803 if (!pszServerName)
1804 {
1805 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1806 ERR("HeapAlloc failed!\n");
1807 goto Cleanup;
1808 }
1809
1810 WideCharToMultiByte(CP_ACP, 0, ppi4w[i].pServerName, -1, pszServerName, cch + 1, NULL, NULL);
1811 StringCchCopyA(ppi4a[i].pServerName, cch + 1, pszServerName);
1812
1813 HeapFree(hProcessHeap, 0, pszServerName);
1814 }
1815 break;
1816 }
1817
1818 case 5:
1819 {
1820 if (ppi5w[i].pPrinterName)
1821 {
1822 // Convert Unicode pPrinterName to a ANSI string pszPrinterName.
1823 cch = wcslen(ppi5w[i].pPrinterName);
1824
1825 pszPrinterName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1826 if (!pszPrinterName)
1827 {
1828 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1829 ERR("HeapAlloc failed!\n");
1830 goto Cleanup;
1831 }
1832
1833 WideCharToMultiByte(CP_ACP, 0, ppi5w[i].pPrinterName, -1, pszPrinterName, cch + 1, NULL, NULL);
1834 StringCchCopyA(ppi5a[i].pPrinterName, cch + 1, pszPrinterName);
1835
1836 HeapFree(hProcessHeap, 0, pszPrinterName);
1837 }
1838
1839 if (ppi5w[i].pPortName)
1840 {
1841 // Convert Unicode pPortName to a ANSI string pszPortName.
1842 cch = wcslen(ppi5w[i].pPortName);
1843
1844 pszPortName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
1845 if (!pszPortName)
1846 {
1847 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1848 ERR("HeapAlloc failed!\n");
1849 goto Cleanup;
1850 }
1851
1852 WideCharToMultiByte(CP_ACP, 0, ppi5w[i].pPortName, -1, pszPortName, cch + 1, NULL, NULL);
1853 StringCchCopyA(ppi5a[i].pPortName, cch + 1, pszPortName);
1854
1855 HeapFree(hProcessHeap, 0, pszPortName);
1856 }
1857 break;
1858 }
1859
1860 } // switch
1861 } // for
1862
1863 dwErrorCode = ERROR_SUCCESS;
1864
1865Cleanup:
1866 if (pwszName)
1867 {
1868 HeapFree(hProcessHeap, 0, pwszName);
1869 }
1870
1871 SetLastError(dwErrorCode);
1872 return (dwErrorCode == ERROR_SUCCESS);
1873}
#define WideCharToMultiByte
Definition: compat.h:111
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:145
char * PSTR
Definition: typedefs.h:51
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3828
struct _PRINTER_INFO_2A * PPRINTER_INFO_2A
struct _PRINTER_INFO_1A * PPRINTER_INFO_1A
WINBOOL WINAPI EnumPrintersW(DWORD Flags, LPWSTR Name, DWORD Level, LPBYTE pPrinterEnum, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
struct _PRINTER_INFO_4W * PPRINTER_INFO_4W
struct _PRINTER_INFO_1W * PPRINTER_INFO_1W
struct _PRINTER_INFO_4A * PPRINTER_INFO_4A
struct _PRINTER_INFO_5A * PPRINTER_INFO_5A
struct _PRINTER_INFO_5W * PPRINTER_INFO_5W
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
char CHAR
Definition: xmlstorage.h:175

◆ EnumPrintersW()

BOOL WINAPI EnumPrintersW ( DWORD  Flags,
PWSTR  Name,
DWORD  Level,
PBYTE  pPrinterEnum,
DWORD  cbBuf,
PDWORD  pcbNeeded,
PDWORD  pcReturned 
)

Definition at line 1876 of file printers.c.

1877{
1878 DWORD dwErrorCode;
1879
1880 TRACE("EnumPrintersW(%lu, %S, %lu, %p, %lu, %p, %p)\n", Flags, Name, Level, pPrinterEnum, cbBuf, pcbNeeded, pcReturned);
1881
1882 // Dismiss invalid levels already at this point.
1883 if (Level == 3 || Level > 5)
1884 {
1885 dwErrorCode = ERROR_INVALID_LEVEL;
1886 goto Cleanup;
1887 }
1888
1889 if (cbBuf && pPrinterEnum)
1890 ZeroMemory(pPrinterEnum, cbBuf);
1891
1892 // Do the RPC call
1894 {
1895 dwErrorCode = _RpcEnumPrinters(Flags, Name, Level, pPrinterEnum, cbBuf, pcbNeeded, pcReturned);
1896 }
1898 {
1899 dwErrorCode = RpcExceptionCode();
1900 ERR("_RpcEnumPrinters failed with exception code %lu!\n", dwErrorCode);
1901 }
1903
1904 if (dwErrorCode == ERROR_SUCCESS)
1905 {
1906 // Replace relative offset addresses in the output by absolute pointers.
1907 ASSERT(Level <= 9);
1908 MarshallUpStructuresArray(cbBuf, pPrinterEnum, *pcReturned, pPrinterInfoMarshalling[Level]->pInfo, pPrinterInfoMarshalling[Level]->cbStructureSize, TRUE);
1909 }
1910
1911Cleanup:
1912 SetLastError(dwErrorCode);
1913 return (dwErrorCode == ERROR_SUCCESS);
1914}
DWORD _RpcEnumPrinters(DWORD Flags, WINSPOOL_HANDLE Name, DWORD Level, BYTE *pPrinterEnum, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
Definition: printers.c:123
BOOL WINAPI MarshallUpStructuresArray(DWORD cbSize, PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:202
#define ASSERT(a)
Definition: mode.c:44
static const MARSHALLING * pPrinterInfoMarshalling[]
Definition: printers.h:146
#define ZeroMemory
Definition: winbase.h:1712

◆ file_dlg_proc()

INT_PTR CALLBACK file_dlg_proc ( HWND  hwnd,
UINT  msg,
WPARAM  wparam,
LPARAM  lparam 
)

Definition at line 3509 of file printers.c.

3510{
3512
3513 switch(msg)
3514 {
3515 case WM_INITDIALOG:
3517 return TRUE;
3518
3519 case WM_COMMAND:
3520 if(HIWORD(wparam) == BN_CLICKED)
3521 {
3522 if(LOWORD(wparam) == IDOK)
3523 {
3524 HANDLE hf;
3526 LPWSTR *output;
3527
3528 filename = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
3529 if (!filename)
3530 {
3531 ERR("Failed to allocate filename of %u bytes\n", (len + 1) * sizeof(WCHAR));
3532 return FALSE;
3533 }
3535
3537 {
3538 WCHAR caption[200], message[200];
3539 int mb_ret;
3540
3541 LoadStringW(hinstWinSpool, IDS_CAPTION, caption, ARRAYSIZE(caption));
3543 mb_ret = MessageBoxW(hwnd, message, caption, MB_OKCANCEL | MB_ICONEXCLAMATION);
3544 if(mb_ret == IDCANCEL)
3545 {
3547 return TRUE;
3548 }
3549 }
3551 if(hf == INVALID_HANDLE_VALUE)
3552 {
3553 WCHAR caption[200], message[200];
3554
3555 LoadStringW(hinstWinSpool, IDS_CAPTION, caption, ARRAYSIZE(caption));
3559 return TRUE;
3560 }
3561 CloseHandle(hf);
3563 output = (LPWSTR *)GetWindowLongPtrW(hwnd, DWLP_USER);
3564 *output = filename;
3566 return TRUE;
3567 }
3568 if(LOWORD(wparam) == IDCANCEL)
3569 {
3571 return TRUE;
3572 }
3573 }
3574 return FALSE;
3575 }
3576 return FALSE;
3577}
@ wparam
Definition: SystemMenu.c:30
#define msg(x)
Definition: auth_time.c:54
#define IDS_CANNOT_OPEN
Definition: resource.h:8
#define IDS_CAPTION
Definition: resource.h:93
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
GLenum GLsizei len
Definition: glext.h:6722
const char * filename
Definition: ioapi.h:137
#define LOWORD(l)
Definition: pedump.c:82
Definition: tftpd.h:60
#define HIWORD(l)
Definition: typedefs.h:247
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2263
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define WM_GETTEXTLENGTH
Definition: winuser.h:1619
#define DWLP_USER
Definition: winuser.h:872
#define GetWindowLongPtrW
Definition: winuser.h:4829
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_INITDIALOG
Definition: winuser.h:1739
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define MB_OKCANCEL
Definition: winuser.h:804
#define MB_ICONEXCLAMATION
Definition: winuser.h:785
#define MB_OK
Definition: winuser.h:790
#define BN_CLICKED
Definition: winuser.h:1925
#define SetWindowLongPtrW
Definition: winuser.h:5355
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
#define IDS_FILE_EXISTS
Definition: wspool.h:26
#define EDITBOX
Definition: wspool.h:30

Referenced by StartDocDlgW().

◆ FlushPrinter()

BOOL WINAPI FlushPrinter ( HANDLE  hPrinter,
PVOID  pBuf,
DWORD  cbBuf,
PDWORD  pcWritten,
DWORD  cSleep 
)

Definition at line 1917 of file printers.c.

1918{
1919 TRACE("FlushPrinter(%p, %p, %lu, %p, %lu)\n", hPrinter, pBuf, cbBuf, pcWritten, cSleep);
1921 return FALSE;
1922}

◆ get_devmodeW()

PRINTER_INFO_9W * get_devmodeW ( HANDLE  hprn)

Definition at line 746 of file printers.c.

747{
748 PRINTER_INFO_9W *pi9 = NULL;
749 DWORD needed = 0;
750 BOOL res;
751
752 res = GetPrinterW(hprn, 9, NULL, 0, &needed);
754 {
755 pi9 = HeapAlloc(hProcessHeap, 0, needed);
756 if (!pi9)
757 {
758 ERR("Failed to allocate PRINTER_INFO_9W of %u bytes\n", needed);
759 return NULL;
760 }
761 res = GetPrinterW(hprn, 9, (LPBYTE)pi9, needed, &needed);
762 }
763
764 if (res)
765 return pi9;
766
767 ERR("GetPrinterW failed with %u\n", GetLastError());
768 HeapFree(hProcessHeap, 0, pi9);
769 return NULL;
770}
GLuint res
Definition: glext.h:9613
WINBOOL WINAPI GetPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD pcbNeeded)
Definition: printers.c:2533

Referenced by DocumentPropertySheets().

◆ GetDefaultPrinterA()

BOOL WINAPI GetDefaultPrinterA ( LPSTR  pszBuffer,
LPDWORD  pcchBuffer 
)

Definition at line 1925 of file printers.c.

1926{
1927 DWORD dwErrorCode;
1928 PWSTR pwszBuffer = NULL;
1929
1930 TRACE("GetDefaultPrinterA(%p, %p)\n", pszBuffer, pcchBuffer);
1931
1932 // Sanity check.
1933 if (!pcchBuffer)
1934 {
1935 dwErrorCode = ERROR_INVALID_PARAMETER;
1936 goto Cleanup;
1937 }
1938
1939 // Check if an ANSI buffer was given and if so, allocate a Unicode buffer of the same size.
1940 if (pszBuffer && *pcchBuffer)
1941 {
1942 pwszBuffer = HeapAlloc(hProcessHeap, 0, *pcchBuffer * sizeof(WCHAR));
1943 if (!pwszBuffer)
1944 {
1945 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
1946 ERR("HeapAlloc failed!\n");
1947 goto Cleanup;
1948 }
1949 }
1950
1951 if (!GetDefaultPrinterW(pwszBuffer, pcchBuffer))
1952 {
1953 dwErrorCode = GetLastError();
1954 goto Cleanup;
1955 }
1956
1957 // We successfully got a string in pwszBuffer, so convert the Unicode string to ANSI.
1958 WideCharToMultiByte(CP_ACP, 0, pwszBuffer, -1, pszBuffer, *pcchBuffer, NULL, NULL);
1959
1960 dwErrorCode = ERROR_SUCCESS;
1961
1962Cleanup:
1963 if (pwszBuffer)
1964 HeapFree(hProcessHeap, 0, pwszBuffer);
1965
1966 SetLastError(dwErrorCode);
1967 return (dwErrorCode == ERROR_SUCCESS);
1968}
BOOL WINAPI GetDefaultPrinterW(LPWSTR pszBuffer, LPDWORD pcchBuffer)
Definition: printers.c:1971

Referenced by PRINTDLG_CreateDevNames(), PRINTDLG_SetUpPrinterListComboA(), PRINTDLG_WMInitDialog(), and START_TEST().

◆ GetDefaultPrinterW()

BOOL WINAPI GetDefaultPrinterW ( LPWSTR  pszBuffer,
LPDWORD  pcchBuffer 
)

Definition at line 1971 of file printers.c.

1972{
1973 DWORD cbNeeded;
1974 DWORD cchInputBuffer;
1975 DWORD dwErrorCode;
1976 HKEY hWindowsKey = NULL;
1977 PWSTR pwszDevice = NULL;
1978 PWSTR pwszComma;
1979
1980 TRACE("GetDefaultPrinterW(%p, %p)\n", pszBuffer, pcchBuffer);
1981
1982 // Sanity check.
1983 if (!pcchBuffer)
1984 {
1985 dwErrorCode = ERROR_INVALID_PARAMETER;
1986 goto Cleanup;
1987 }
1988
1989 cchInputBuffer = *pcchBuffer;
1990
1991 // Open the registry key where the default printer for the current user is stored.
1992 dwErrorCode = (DWORD)RegOpenKeyExW(HKEY_CURRENT_USER, wszWindowsKey, 0, KEY_READ, &hWindowsKey);
1993 if (dwErrorCode != ERROR_SUCCESS)
1994 {
1995 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode);
1996 goto Cleanup;
1997 }
1998
1999 // Determine the size of the required buffer.
2000 dwErrorCode = (DWORD)RegQueryValueExW(hWindowsKey, wszDeviceValue, NULL, NULL, NULL, &cbNeeded);
2001 if (dwErrorCode != ERROR_SUCCESS)
2002 {
2003 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode);
2004 goto Cleanup;
2005 }
2006
2007 // Allocate it.
2008 pwszDevice = HeapAlloc(hProcessHeap, 0, cbNeeded);
2009 if (!pwszDevice)
2010 {
2011 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2012 ERR("HeapAlloc failed!\n");
2013 goto Cleanup;
2014 }
2015
2016 // Now get the actual value.
2017 dwErrorCode = RegQueryValueExW(hWindowsKey, wszDeviceValue, NULL, NULL, (PBYTE)pwszDevice, &cbNeeded);
2018 if (dwErrorCode != ERROR_SUCCESS)
2019 {
2020 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode);
2021 goto Cleanup;
2022 }
2023
2024 // We get a string "<Printer Name>,winspool,<Port>:".
2025 // Extract the printer name from it.
2026 pwszComma = wcschr(pwszDevice, L',');
2027 if (!pwszComma)
2028 {
2029 ERR("Found no or invalid default printer: %S!\n", pwszDevice);
2030 dwErrorCode = ERROR_INVALID_NAME;
2031 goto Cleanup;
2032 }
2033
2034 // Store the length of the Printer Name (including the terminating NUL character!) in *pcchBuffer.
2035 *pcchBuffer = pwszComma - pwszDevice + 1;
2036
2037 // Check if the supplied buffer is large enough.
2038 if ( !pszBuffer || cchInputBuffer < *pcchBuffer)
2039 {
2040 dwErrorCode = ERROR_INSUFFICIENT_BUFFER;
2041 goto Cleanup;
2042 }
2043
2044 // Copy the default printer.
2045 *pwszComma = 0;
2046 CopyMemory(pszBuffer, pwszDevice, *pcchBuffer * sizeof(WCHAR));
2047
2048 dwErrorCode = ERROR_SUCCESS;
2049
2050Cleanup:
2051 if (hWindowsKey)
2052 RegCloseKey(hWindowsKey);
2053
2054 if (pwszDevice)
2055 HeapFree(hProcessHeap, 0, pwszDevice);
2056
2057 SetLastError(dwErrorCode);
2058 return (dwErrorCode == ERROR_SUCCESS);
2059}
static const WCHAR wszWindowsKey[]
Definition: printers.c:61
static const WCHAR wszDeviceValue[]
Definition: printers.c:62
#define RegCloseKey(hKey)
Definition: registry.h:49
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define wcschr
Definition: compat.h:17
#define ERROR_INVALID_NAME
Definition: compat.h:103
#define KEY_READ
Definition: nt_native.h:1023
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
#define CopyMemory
Definition: winbase.h:1710
#define HKEY_CURRENT_USER
Definition: winreg.h:11

Referenced by get_default_printer(), GetDefaultPrinterA(), pagesetup_set_devnames(), PRINTDLG_CreateDevNamesW(), PRINTDLG_OpenDefaultPrinter(), PRINTDLG_SetUpPrinterListComboW(), PRINTDLG_WMInitDialogW(), SetDefaultPrinterW(), and START_TEST().

◆ GetPrinterA()

BOOL WINAPI GetPrinterA ( HANDLE  hPrinter,
DWORD  Level,
LPBYTE  pPrinter,
DWORD  cbBuf,
LPDWORD  pcbNeeded 
)

Definition at line 2062 of file printers.c.

2063{
2064 DWORD dwErrorCode;
2065 PPRINTER_INFO_1A ppi1a = (PPRINTER_INFO_1A)pPrinter;
2066 PPRINTER_INFO_1W ppi1w = (PPRINTER_INFO_1W)pPrinter;
2067 PPRINTER_INFO_2A ppi2a = (PPRINTER_INFO_2A)pPrinter;
2068 PPRINTER_INFO_2W ppi2w = (PPRINTER_INFO_2W)pPrinter;
2069 PPRINTER_INFO_4A ppi4a = (PPRINTER_INFO_4A)pPrinter;
2070 PPRINTER_INFO_4W ppi4w = (PPRINTER_INFO_4W)pPrinter;
2071 PPRINTER_INFO_5A ppi5a = (PPRINTER_INFO_5A)pPrinter;
2072 PPRINTER_INFO_5W ppi5w = (PPRINTER_INFO_5W)pPrinter;
2073 PPRINTER_INFO_7A ppi7a = (PPRINTER_INFO_7A)pPrinter;
2074 PPRINTER_INFO_7W ppi7w = (PPRINTER_INFO_7W)pPrinter;
2075 PPRINTER_INFO_9A ppi9a = (PPRINTER_INFO_9A)pPrinter;
2076 PPRINTER_INFO_9W ppi9w = (PPRINTER_INFO_9W)pPrinter;
2077 DWORD cch;
2078
2079 TRACE("GetPrinterA(%p, %lu, %p, %lu, %p)\n", hPrinter, Level, pPrinter, cbBuf, pcbNeeded);
2080
2081 // Check for invalid levels here for early error return. Should be 1-9.
2082 if (Level < 1 || Level > 9)
2083 {
2084 dwErrorCode = ERROR_INVALID_LEVEL;
2085 ERR("Invalid Level!\n");
2086 goto Cleanup;
2087 }
2088
2089 if (!GetPrinterW(hPrinter, Level, pPrinter, cbBuf, pcbNeeded))
2090 {
2091 dwErrorCode = GetLastError();
2092 goto Cleanup;
2093 }
2094
2095 switch (Level)
2096 {
2097 case 1:
2098 {
2099 if (ppi1w->pDescription)
2100 {
2101 PSTR pszDescription;
2102
2103 // Convert Unicode pDescription to a ANSI string pszDescription.
2104 cch = wcslen(ppi1w->pDescription);
2105
2106 pszDescription = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2107 if (!pszDescription)
2108 {
2109 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2110 ERR("HeapAlloc failed!\n");
2111 goto Cleanup;
2112 }
2113
2114 WideCharToMultiByte(CP_ACP, 0, ppi1w->pDescription, -1, pszDescription, cch + 1, NULL, NULL);
2115 StringCchCopyA(ppi1a->pDescription, cch + 1, pszDescription);
2116
2117 HeapFree(hProcessHeap, 0, pszDescription);
2118 }
2119
2120 if (ppi1w->pName)
2121 {
2122 PSTR pszName;
2123
2124 // Convert Unicode pName to a ANSI string pszName.
2125 cch = wcslen(ppi1w->pName);
2126
2127 pszName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2128 if (!pszName)
2129 {
2130 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2131 ERR("HeapAlloc failed!\n");
2132 goto Cleanup;
2133 }
2134
2135 WideCharToMultiByte(CP_ACP, 0, ppi1w->pName, -1, pszName, cch + 1, NULL, NULL);
2136 StringCchCopyA(ppi1a->pName, cch + 1, pszName);
2137
2138 HeapFree(hProcessHeap, 0, pszName);
2139 }
2140
2141 if (ppi1w->pComment)
2142 {
2143 PSTR pszComment;
2144
2145 // Convert Unicode pComment to a ANSI string pszComment.
2146 cch = wcslen(ppi1w->pComment);
2147
2148 pszComment = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2149 if (!pszComment)
2150 {
2151 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2152 ERR("HeapAlloc failed!\n");
2153 goto Cleanup;
2154 }
2155
2156 WideCharToMultiByte(CP_ACP, 0, ppi1w->pComment, -1, pszComment, cch + 1, NULL, NULL);
2157 StringCchCopyA(ppi1a->pComment, cch + 1, pszComment);
2158
2159 HeapFree(hProcessHeap, 0, pszComment);
2160 }
2161 break;
2162 }
2163
2164 case 2:
2165 {
2166 if (ppi2w->pServerName)
2167 {
2168 PSTR pszServerName;
2169
2170 // Convert Unicode pServerName to a ANSI string pszServerName.
2171 cch = wcslen(ppi2w->pServerName);
2172
2173 pszServerName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2174 if (!pszServerName)
2175 {
2176 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2177 ERR("HeapAlloc failed!\n");
2178 goto Cleanup;
2179 }
2180
2181 WideCharToMultiByte(CP_ACP, 0, ppi2w->pServerName, -1, pszServerName, cch + 1, NULL, NULL);
2182 StringCchCopyA(ppi2a->pServerName, cch + 1, pszServerName);
2183
2184 HeapFree(hProcessHeap, 0, pszServerName);
2185 }
2186
2187 if (ppi2w->pPrinterName)
2188 {
2189 PSTR pszPrinterName;
2190
2191 // Convert Unicode pPrinterName to a ANSI string pszPrinterName.
2192 cch = wcslen(ppi2w->pPrinterName);
2193
2194 pszPrinterName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2195 if (!pszPrinterName)
2196 {
2197 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2198 ERR("HeapAlloc failed!\n");
2199 goto Cleanup;
2200 }
2201
2202 WideCharToMultiByte(CP_ACP, 0, ppi2w->pPrinterName, -1, pszPrinterName, cch + 1, NULL, NULL);
2203 StringCchCopyA(ppi2a->pPrinterName, cch + 1, pszPrinterName);
2204
2205 HeapFree(hProcessHeap, 0, pszPrinterName);
2206 }
2207
2208 if (ppi2w->pShareName)
2209 {
2210 PSTR pszShareName;
2211
2212 // Convert Unicode pShareName to a ANSI string pszShareName.
2213 cch = wcslen(ppi2w->pShareName);
2214
2215 pszShareName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2216 if (!pszShareName)
2217 {
2218 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2219 ERR("HeapAlloc failed!\n");
2220 goto Cleanup;
2221 }
2222
2223 WideCharToMultiByte(CP_ACP, 0, ppi2w->pShareName, -1, pszShareName, cch + 1, NULL, NULL);
2224 StringCchCopyA(ppi2a->pShareName, cch + 1, pszShareName);
2225
2226 HeapFree(hProcessHeap, 0, pszShareName);
2227 }
2228
2229 if (ppi2w->pPortName)
2230 {
2231 PSTR pszPortName;
2232
2233 // Convert Unicode pPortName to a ANSI string pszPortName.
2234 cch = wcslen(ppi2w->pPortName);
2235
2236 pszPortName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2237 if (!pszPortName)
2238 {
2239 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2240 ERR("HeapAlloc failed!\n");
2241 goto Cleanup;
2242 }
2243
2244 WideCharToMultiByte(CP_ACP, 0, ppi2w->pPortName, -1, pszPortName, cch + 1, NULL, NULL);
2245 StringCchCopyA(ppi2a->pPortName, cch + 1, pszPortName);
2246
2247 HeapFree(hProcessHeap, 0, pszPortName);
2248 }
2249
2250 if (ppi2w->pDriverName)
2251 {
2252 PSTR pszDriverName;
2253
2254 // Convert Unicode pDriverName to a ANSI string pszDriverName.
2255 cch = wcslen(ppi2w->pDriverName);
2256
2257 pszDriverName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2258 if (!pszDriverName)
2259 {
2260 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2261 ERR("HeapAlloc failed!\n");
2262 goto Cleanup;
2263 }
2264
2265 WideCharToMultiByte(CP_ACP, 0, ppi2w->pDriverName, -1, pszDriverName, cch + 1, NULL, NULL);
2266 StringCchCopyA(ppi2a->pDriverName, cch + 1, pszDriverName);
2267
2268 HeapFree(hProcessHeap, 0, pszDriverName);
2269 }
2270
2271 if (ppi2w->pComment)
2272 {
2273 PSTR pszComment;
2274
2275 // Convert Unicode pComment to a ANSI string pszComment.
2276 cch = wcslen(ppi2w->pComment);
2277
2278 pszComment = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2279 if (!pszComment)
2280 {
2281 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2282 ERR("HeapAlloc failed!\n");
2283 goto Cleanup;
2284 }
2285
2286 WideCharToMultiByte(CP_ACP, 0, ppi2w->pComment, -1, pszComment, cch + 1, NULL, NULL);
2287 StringCchCopyA(ppi2a->pComment, cch + 1, pszComment);
2288
2289 HeapFree(hProcessHeap, 0, pszComment);
2290 }
2291
2292 if (ppi2w->pLocation)
2293 {
2294 PSTR pszLocation;
2295
2296 // Convert Unicode pLocation to a ANSI string pszLocation.
2297 cch = wcslen(ppi2w->pLocation);
2298
2299 pszLocation = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2300 if (!pszLocation)
2301 {
2302 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2303 ERR("HeapAlloc failed!\n");
2304 goto Cleanup;
2305 }
2306
2307 WideCharToMultiByte(CP_ACP, 0, ppi2w->pLocation, -1, pszLocation, cch + 1, NULL, NULL);
2308 StringCchCopyA(ppi2a->pLocation, cch + 1, pszLocation);
2309
2310 HeapFree(hProcessHeap, 0, pszLocation);
2311 }
2312
2313 if (ppi2w->pSepFile)
2314 {
2315 PSTR pszSepFile;
2316
2317 // Convert Unicode pSepFile to a ANSI string pszSepFile.
2318 cch = wcslen(ppi2w->pSepFile);
2319
2320 pszSepFile = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2321 if (!pszSepFile)
2322 {
2323 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2324 ERR("HeapAlloc failed!\n");
2325 goto Cleanup;
2326 }
2327
2328 WideCharToMultiByte(CP_ACP, 0, ppi2w->pSepFile, -1, pszSepFile, cch + 1, NULL, NULL);
2329 StringCchCopyA(ppi2a->pSepFile, cch + 1, pszSepFile);
2330
2331 HeapFree(hProcessHeap, 0, pszSepFile);
2332 }
2333
2334 if (ppi2w->pPrintProcessor)
2335 {
2336 PSTR pszPrintProcessor;
2337
2338 // Convert Unicode pPrintProcessor to a ANSI string pszPrintProcessor.
2339 cch = wcslen(ppi2w->pPrintProcessor);
2340
2341 pszPrintProcessor = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2342 if (!pszPrintProcessor)
2343 {
2344 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2345 ERR("HeapAlloc failed!\n");
2346 goto Cleanup;
2347 }
2348
2349 WideCharToMultiByte(CP_ACP, 0, ppi2w->pPrintProcessor, -1, pszPrintProcessor, cch + 1, NULL, NULL);
2350 StringCchCopyA(ppi2a->pPrintProcessor, cch + 1, pszPrintProcessor);
2351
2352 HeapFree(hProcessHeap, 0, pszPrintProcessor);
2353 }
2354
2355 if (ppi2w->pDatatype)
2356 {
2357 PSTR pszDatatype;
2358
2359 // Convert Unicode pDatatype to a ANSI string pszDatatype.
2360 cch = wcslen(ppi2w->pDatatype);
2361
2362 pszDatatype = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2363 if (!pszDatatype)
2364 {
2365 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2366 ERR("HeapAlloc failed!\n");
2367 goto Cleanup;
2368 }
2369
2370 WideCharToMultiByte(CP_ACP, 0, ppi2w->pDatatype, -1, pszDatatype, cch + 1, NULL, NULL);
2371 StringCchCopyA(ppi2a->pDatatype, cch + 1, pszDatatype);
2372
2373 HeapFree(hProcessHeap, 0, pszDatatype);
2374 }
2375
2376 if (ppi2w->pParameters)
2377 {
2378 PSTR pszParameters;
2379
2380 // Convert Unicode pParameters to a ANSI string pszParameters.
2381 cch = wcslen(ppi2w->pParameters);
2382
2383 pszParameters = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2384 if (!pszParameters)
2385 {
2386 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2387 ERR("HeapAlloc failed!\n");
2388 goto Cleanup;
2389 }
2390
2391 WideCharToMultiByte(CP_ACP, 0, ppi2w->pParameters, -1, pszParameters, cch + 1, NULL, NULL);
2392 StringCchCopyA(ppi2a->pParameters, cch + 1, pszParameters);
2393
2394 HeapFree(hProcessHeap, 0, pszParameters);
2395 }
2396 if ( ppi2w->pDevMode )
2397 {
2399 }
2400 break;
2401 }
2402
2403 case 4:
2404 {
2405 if (ppi4w->pPrinterName)
2406 {
2407 PSTR pszPrinterName;
2408
2409 // Convert Unicode pPrinterName to a ANSI string pszPrinterName.
2410 cch = wcslen(ppi4w->pPrinterName);
2411
2412 pszPrinterName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2413 if (!pszPrinterName)
2414 {
2415 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2416 ERR("HeapAlloc failed!\n");
2417 goto Cleanup;
2418 }
2419
2420 WideCharToMultiByte(CP_ACP, 0, ppi4w->pPrinterName, -1, pszPrinterName, cch + 1, NULL, NULL);
2421 StringCchCopyA(ppi4a->pPrinterName, cch + 1, pszPrinterName);
2422
2423 HeapFree(hProcessHeap, 0, pszPrinterName);
2424 }
2425
2426 if (ppi4w->pServerName)
2427 {
2428 PSTR pszServerName;
2429
2430 // Convert Unicode pServerName to a ANSI string pszServerName.
2431 cch = wcslen(ppi4w->pServerName);
2432
2433 pszServerName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2434 if (!pszServerName)
2435 {
2436 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2437 ERR("HeapAlloc failed!\n");
2438 goto Cleanup;
2439 }
2440
2441 WideCharToMultiByte(CP_ACP, 0, ppi4w->pServerName, -1, pszServerName, cch + 1, NULL, NULL);
2442 StringCchCopyA(ppi4a->pServerName, cch + 1, pszServerName);
2443
2444 HeapFree(hProcessHeap, 0, pszServerName);
2445 }
2446 break;
2447 }
2448
2449 case 5:
2450 {
2451 if (ppi5w->pPrinterName)
2452 {
2453 PSTR pszPrinterName;
2454
2455 // Convert Unicode pPrinterName to a ANSI string pszPrinterName.
2456 cch = wcslen(ppi5w->pPrinterName);
2457
2458 pszPrinterName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2459 if (!pszPrinterName)
2460 {
2461 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2462 ERR("HeapAlloc failed!\n");
2463 goto Cleanup;
2464 }
2465
2466 WideCharToMultiByte(CP_ACP, 0, ppi5w->pPrinterName, -1, pszPrinterName, cch + 1, NULL, NULL);
2467 StringCchCopyA(ppi5a->pPrinterName, cch + 1, pszPrinterName);
2468
2469 HeapFree(hProcessHeap, 0, pszPrinterName);
2470 }
2471
2472 if (ppi5w->pPortName)
2473 {
2474 PSTR pszPortName;
2475
2476 // Convert Unicode pPortName to a ANSI string pszPortName.
2477 cch = wcslen(ppi5w->pPortName);
2478
2479 pszPortName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2480 if (!pszPortName)
2481 {
2482 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2483 ERR("HeapAlloc failed!\n");
2484 goto Cleanup;
2485 }
2486
2487 WideCharToMultiByte(CP_ACP, 0, ppi5w->pPortName, -1, pszPortName, cch + 1, NULL, NULL);
2488 StringCchCopyA(ppi5a->pPortName, cch + 1, pszPortName);
2489
2490 HeapFree(hProcessHeap, 0, pszPortName);
2491 }
2492 break;
2493 }
2494
2495 case 7:
2496 {
2497 if (ppi7w->pszObjectGUID)
2498 {
2499 PSTR pszaObjectGUID;
2500
2501 // Convert Unicode pszObjectGUID to a ANSI string pszaObjectGUID.
2502 cch = wcslen(ppi7w->pszObjectGUID);
2503
2504 pszaObjectGUID = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
2505 if (!pszaObjectGUID)
2506 {
2507 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2508 ERR("HeapAlloc failed!\n");
2509 goto Cleanup;
2510 }
2511
2512 WideCharToMultiByte(CP_ACP, 0, ppi7w->pszObjectGUID, -1, pszaObjectGUID, cch + 1, NULL, NULL);
2513 StringCchCopyA(ppi7a->pszObjectGUID, cch + 1, pszaObjectGUID);
2514
2515 HeapFree(hProcessHeap, 0, pszaObjectGUID);
2516 }
2517 }
2518 break;
2519 case 8:
2520 case 9:
2522 break;
2523 } // switch
2524
2525 dwErrorCode = ERROR_SUCCESS;
2526
2527Cleanup:
2528 SetLastError(dwErrorCode);
2529 return (dwErrorCode == ERROR_SUCCESS);
2530}
LPSTR pComment
Definition: winspool.h:23
LPSTR pDescription
Definition: winspool.h:21
LPWSTR pName
Definition: winspool.h:29
LPWSTR pComment
Definition: winspool.h:30
LPWSTR pDescription
Definition: winspool.h:28
LPWSTR pServerName
Definition: winspool.h:62
LPSTR pPrinterName
Definition: winspool.h:94
LPSTR pServerName
Definition: winspool.h:95
LPWSTR pServerName
Definition: winspool.h:101
LPWSTR pPrinterName
Definition: winspool.h:100
LPSTR pPrinterName
Definition: winspool.h:110
LPWSTR pPrinterName
Definition: winspool.h:118
LPWSTR pPortName
Definition: winspool.h:119
LPSTR pszObjectGUID
Definition: winspool.h:134
LPWSTR pszObjectGUID
Definition: winspool.h:139
LPDEVMODEA pDevMode
Definition: winspool.h:166
struct _PRINTER_INFO_9A * PPRINTER_INFO_9A
struct _PRINTER_INFO_7W * PPRINTER_INFO_7W
struct _PRINTER_INFO_7A * PPRINTER_INFO_7A
struct _PRINTER_INFO_9W * PPRINTER_INFO_9W

Referenced by get_printer_infoA(), PRINTDLG_ChangePrinterA(), PrintDlgA(), test_GetPrinter(), and test_OpenPrinter_defaults().

◆ GetPrinterW()

BOOL WINAPI GetPrinterW ( HANDLE  hPrinter,
DWORD  Level,
LPBYTE  pPrinter,
DWORD  cbBuf,
LPDWORD  pcbNeeded 
)

Definition at line 2533 of file printers.c.

2534{
2535 DWORD dwErrorCode;
2536 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
2537
2538 TRACE("GetPrinterW(%p, %lu, %p, %lu, %p)\n", hPrinter, Level, pPrinter, cbBuf, pcbNeeded);
2539
2540 // Sanity checks.
2541 if (!pHandle)
2542 {
2543 dwErrorCode = ERROR_INVALID_HANDLE;
2544 goto Cleanup;
2545 }
2546
2547 // Dismiss invalid levels already at this point.
2548 if (Level > 9)
2549 {
2550 dwErrorCode = ERROR_INVALID_LEVEL;
2551 goto Cleanup;
2552 }
2553
2554 if (cbBuf && pPrinter)
2555 ZeroMemory(pPrinter, cbBuf);
2556
2557 // Do the RPC call
2559 {
2560 dwErrorCode = _RpcGetPrinter(pHandle->hPrinter, Level, pPrinter, cbBuf, pcbNeeded);
2561 }
2563 {
2564 dwErrorCode = RpcExceptionCode();
2565 ERR("_RpcGetPrinter failed with exception code %lu!\n", dwErrorCode);
2566 }
2568
2569 if (dwErrorCode == ERROR_SUCCESS)
2570 {
2571 // Replace relative offset addresses in the output by absolute pointers.
2572 ASSERT(Level <= 9);
2573 MarshallUpStructure(cbBuf, pPrinter, pPrinterInfoMarshalling[Level]->pInfo, pPrinterInfoMarshalling[Level]->cbStructureSize, TRUE);
2574 }
2575
2576Cleanup:
2577 SetLastError(dwErrorCode);
2578 return (dwErrorCode == ERROR_SUCCESS);
2579}
DWORD _RpcGetPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD Level, BYTE *pPrinter, DWORD cbBuf, DWORD *pcbNeeded)
Definition: printers.c:162
BOOL WINAPI MarshallUpStructure(DWORD cbSize, PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:137

Referenced by get_printer_infoW(), pagesetup_change_printer(), PRINTDLG_ChangePrinterW(), PrintDlgW(), START_TEST(), and UpdateTrayIcon().

◆ IntFixUpDevModeNames()

BOOL FASTCALL IntFixUpDevModeNames ( PDOCUMENTPROPERTYHEADER  pdphdr)

Definition at line 820 of file printers.c.

821{
822 PRINTER_INFO_2W *pi2 = NULL;
823 DWORD needed = 0;
824 BOOL res;
825
826 if (!(pdphdr->fMode & DM_OUT_BUFFER) ||
827 pdphdr->fMode & DM_NOPERMISSION || // Do not allow the user to modify properties on the displayed property sheet pages.
828 !pdphdr->pdmOut )
829 {
830 return FALSE;
831 }
832
833 res = GetPrinterW( pdphdr->hPrinter, 2, NULL, 0, &needed);
835 {
836 pi2 = HeapAlloc(hProcessHeap, 0, needed);
837 if (!pi2)
838 {
839 ERR("Failed to allocate PRINTER_INFO_2W of %u bytes\n", needed);
840 return FALSE;
841 }
842 res = GetPrinterW( pdphdr->hPrinter, 2, (LPBYTE)pi2, needed, &needed);
843 }
844
845 if (res)
846 {
847 /* Check if the provided buffer is large enough */
848 DWORD cbDevMode = pi2->pDevMode->dmSize + pi2->pDevMode->dmDriverExtra;
849 if (pdphdr->cbOut < cbDevMode)
850 {
851 ERR("cbOut (%lu) < cbDevMode(%u)\n", pdphdr->cbOut, cbDevMode);
852 res = FALSE;
853 goto Exit;
854 }
855
856 /* Copy the devmode */
857 RtlCopyMemory(pdphdr->pdmOut, pi2->pDevMode, cbDevMode);
858
859 TRACE("IFUDMN : Get Printer Name %S\n", pi2->pPrinterName);
861 pdphdr->pdmOut->dmDeviceName[CCHDEVICENAME-1] = 0;
862 }
863 else
864 {
865 ERR("IFUDMN : GetPrinterW failed with %u\n", GetLastError());
866 }
867
868Exit:
869 HeapFree(hProcessHeap, 0, pi2);
870 return res;
871}
#define CCHDEVICENAME
Definition: ddrawi.h:63
#define DM_NOPERMISSION
Definition: winddiui.h:139
static void Exit(void)
Definition: sock.c:1330
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
BYTE dmDeviceName[CCHDEVICENAME]
Definition: wingdi.h:1565
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define DM_OUT_BUFFER
Definition: windef.h:359

Referenced by DocumentPropertySheets().

◆ LoadPrinterDriver()

HMODULE WINAPI LoadPrinterDriver ( HANDLE  hspool)

Definition at line 488 of file printers.c.

489{
490 INT iTries = 0;
491 DWORD Size = (sizeof(WCHAR) * MAX_PATH) * 2; // DRIVER_INFO_5W + plus strings.
494
495 do
496 {
497 ++iTries;
498
500
501 if ( !pdi )
502 break;
503
504 if ( GetPrinterDriverW(hspool, NULL, 5, (LPBYTE)pdi, Size, &Size) )
505 {
506 TRACE("Level 5 Size %d\n",Size);
507
508 // Name and load configure library (for example, C:\DRIVERS\Pscrptui.dll). Not printui.dll!
509
510 hLibrary = LoadLibrary(pdi->pConfigFile);
511
512 FIXME("IGPD : Get Printer Driver Config File : %S\n",pdi->pConfigFile);
513
515 return hLibrary;
516 }
517
519 ++iTries;
520
522 }
523 while ( iTries < 2 );
524 ERR("No Printer Driver Error %d\n",GetLastError());
525 return NULL;
526}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define MAX_PATH
Definition: compat.h:34
int32_t INT
Definition: typedefs.h:58
#define LoadLibrary
Definition: winbase.h:3862
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO * pdi
Definition: winddi.h:3554
WINBOOL WINAPI GetPrinterDriverW(HANDLE hPrinter, LPWSTR pEnvironment, DWORD Level, LPBYTE pDriverInfo, DWORD cbBuf, LPDWORD pcbNeeded)

Referenced by CreateUIUserData(), DeviceCapabilitiesW(), DevQueryPrint(), DevQueryPrintEx(), DocumentPropertySheets(), QueryColorProfile(), and SpoolerPrinterEvent().

◆ OpenPrinterA()

BOOL WINAPI OpenPrinterA ( LPSTR  pPrinterName,
LPHANDLE  phPrinter,
LPPRINTER_DEFAULTSA  pDefault 
)

Definition at line 2582 of file printers.c.

2583{
2584 BOOL bReturnValue = FALSE;
2585 DWORD cch;
2586 PWSTR pwszPrinterName = NULL;
2587 PRINTER_DEFAULTSW wDefault = { 0 };
2588
2589 TRACE("OpenPrinterA(%s, %p, %p)\n", pPrinterName, phPrinter, pDefault);
2590
2591 if (pPrinterName)
2592 {
2593 // Convert pPrinterName to a Unicode string pwszPrinterName
2594 cch = strlen(pPrinterName);
2595
2596 pwszPrinterName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
2597 if (!pwszPrinterName)
2598 {
2600 ERR("HeapAlloc failed!\n");
2601 goto Cleanup;
2602 }
2603
2604 MultiByteToWideChar(CP_ACP, 0, pPrinterName, -1, pwszPrinterName, cch + 1);
2605 }
2606
2607 if (pDefault)
2608 {
2609 wDefault.DesiredAccess = pDefault->DesiredAccess;
2610
2611 if (pDefault->pDatatype)
2612 {
2613 // Convert pDefault->pDatatype to a Unicode string wDefault.pDatatype
2614 cch = strlen(pDefault->pDatatype);
2615
2616 wDefault.pDatatype = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
2617 if (!wDefault.pDatatype)
2618 {
2620 ERR("HeapAlloc failed!\n");
2621 goto Cleanup;
2622 }
2623
2624 MultiByteToWideChar(CP_ACP, 0, pDefault->pDatatype, -1, wDefault.pDatatype, cch + 1);
2625 }
2626
2627 if (pDefault->pDevMode)
2628 wDefault.pDevMode = GdiConvertToDevmodeW(pDefault->pDevMode);
2629 }
2630
2631 bReturnValue = OpenPrinterW(pwszPrinterName, phPrinter, &wDefault);
2632
2633 if ( bReturnValue )
2634 {
2635 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)*phPrinter;
2636 pHandle->bAnsi = TRUE;
2637 }
2638
2639Cleanup:
2640 if (wDefault.pDatatype)
2641 HeapFree(hProcessHeap, 0, wDefault.pDatatype);
2642
2643 if (wDefault.pDevMode)
2644 HeapFree(hProcessHeap, 0, wDefault.pDevMode);
2645
2646 if (pwszPrinterName)
2647 HeapFree(hProcessHeap, 0, pwszPrinterName);
2648
2649 return bReturnValue;
2650}
LPDEVMODEA pDevMode
Definition: winspool.h:856
ACCESS_MASK DesiredAccess
Definition: winspool.h:857
LPDEVMODEW pDevMode
Definition: winspool.h:862
ACCESS_MASK DesiredAccess
Definition: winspool.h:863
DEVMODEW *WINAPI GdiConvertToDevmodeW(const DEVMODEA *)
Definition: misc.c:969

Referenced by AdvancedSetupDialog(), PRINTDLG_ChangePrinterA(), PRINTDLG_WMCommandA(), test_ClosePrinter(), test_DocumentProperties(), test_EnumForms(), test_GetPrinter(), test_GetPrinterData(), test_GetPrinterDataEx(), test_GetPrinterDriver(), test_OpenPrinter(), test_OpenPrinter_defaults(), test_XcvDataW_MonitorUI(), and test_XcvDataW_PortIsValid().

◆ OpenPrinterW()

BOOL WINAPI OpenPrinterW ( LPWSTR  pPrinterName,
LPHANDLE  phPrinter,
LPPRINTER_DEFAULTSW  pDefault 
)

Definition at line 2653 of file printers.c.

2654{
2655 DWORD dwErrorCode;
2656 HANDLE hPrinter;
2657 PSPOOLER_HANDLE pHandle;
2658 PWSTR pDatatype = NULL;
2659 WINSPOOL_DEVMODE_CONTAINER DevModeContainer = { 0 };
2660 ACCESS_MASK AccessRequired = 0;
2661
2662 TRACE("OpenPrinterW(%S, %p, %p)\n", pPrinterName, phPrinter, pDefault);
2663
2664 // Sanity check
2665 if (!phPrinter)
2666 {
2667 dwErrorCode = ERROR_INVALID_PARAMETER;
2668 goto Cleanup;
2669 }
2670
2671 // Prepare the additional parameters in the format required by _RpcOpenPrinter
2672 if (pDefault)
2673 {
2674 pDatatype = pDefault->pDatatype;
2675 DevModeContainer.cbBuf = sizeof(DEVMODEW);
2676 DevModeContainer.pDevMode = (BYTE*)pDefault->pDevMode;
2677 AccessRequired = pDefault->DesiredAccess;
2678 }
2679
2680 // Do the RPC call
2682 {
2683 dwErrorCode = _RpcOpenPrinter(pPrinterName, &hPrinter, pDatatype, &DevModeContainer, AccessRequired);
2684 }
2686 {
2687 dwErrorCode = RpcExceptionCode();
2688 ERR("_RpcOpenPrinter failed with exception code %lu!\n", dwErrorCode);
2689 }
2691
2692 if (dwErrorCode == ERROR_SUCCESS)
2693 {
2694 // Create a new SPOOLER_HANDLE structure.
2696 if (!pHandle)
2697 {
2698 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
2699 ERR("HeapAlloc failed!\n");
2700 goto Cleanup;
2701 }
2702
2703 pHandle->Sig = SPOOLER_HANDLE_SIG;
2704 pHandle->hPrinter = hPrinter;
2705 pHandle->hSPLFile = INVALID_HANDLE_VALUE;
2707
2708 // Return it as phPrinter.
2709 *phPrinter = (HANDLE)pHandle;
2710 }
2711
2712Cleanup:
2713 SetLastError(dwErrorCode);
2714 return (dwErrorCode == ERROR_SUCCESS);
2715}
DWORD _RpcOpenPrinter(WINSPOOL_HANDLE pPrinterName, WINSPOOL_PRINTER_HANDLE *phPrinter, WCHAR *pDatatype, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, DWORD AccessRequired)
Definition: printers.c:194
ULONG ACCESS_MASK
Definition: nt_native.h:40
struct _devicemodeW DEVMODEW
unsigned char BYTE
Definition: xxhash.c:193

Referenced by GetMonitorUI(), LocalmonStartDocPort(), open_monitor_by_name(), pagesetup_change_printer(), pagesetup_printer_properties(), PRINTDLG_ChangePrinterW(), PRINTDLG_OpenDefaultPrinter(), PRINTDLG_WMCommandW(), PrintRawJob(), START_TEST(), and wmain().

◆ PrinterMessageBoxA()

DWORD WINAPI PrinterMessageBoxA ( HANDLE  hPrinter,
DWORD  Error,
HWND  hWnd,
LPSTR  pText,
LPSTR  pCaption,
DWORD  dwType 
)

Definition at line 2721 of file printers.c.

2722{
2723 return 50;
2724}

◆ PrinterMessageBoxW()

DWORD WINAPI PrinterMessageBoxW ( HANDLE  hPrinter,
DWORD  Error,
HWND  hWnd,
LPWSTR  pText,
LPWSTR  pCaption,
DWORD  dwType 
)

Definition at line 2727 of file printers.c.

2728{
2729 return 50;
2730}

Referenced by _RpcPrinterMessageBox().

◆ PrinterProperties()

BOOL WINAPI PrinterProperties ( HWND  hWnd,
HANDLE  hPrinter 
)

Definition at line 1266 of file printers.c.

1267{
1268 PRINTER_INFO_2W *pi2 = NULL;
1269 DWORD needed = 0;
1270 LONG Ret, Result = 0;
1271 BOOL res;
1272 DEVICEPROPERTYHEADER devprophdr;
1273
1274 FIXME("PrinterProperties(%p, %p)\n", hWnd, hPrinter);
1275
1276 devprophdr.cbSize = sizeof(DEVICEPROPERTYHEADER);
1277 devprophdr.Flags = DPS_NOPERMISSION;
1278 devprophdr.hPrinter = hPrinter;
1279 devprophdr.pszPrinterName = NULL;
1280
1281 res = GetPrinterW( hPrinter, 2, NULL, 0, &needed);
1283 {
1284 pi2 = HeapAlloc(hProcessHeap, 0, needed);
1285 if (!pi2)
1286 {
1287 ERR("Failed to allocate PRINTER_INFO_2W of %u bytes\n", needed);
1288 return FALSE;
1289 }
1290 res = GetPrinterW(hPrinter, 2, (LPBYTE)pi2, needed, &needed);
1291 }
1292
1293 //
1294 // Above can fail, still process w/o printer name.
1295 //
1296 if ( res ) devprophdr.pszPrinterName = pi2->pPrinterName;
1297
1298 needed = 1;
1299
1300 if ( ( SetPrinterDataW( hPrinter, L"PrinterPropertiesPermission", REG_DWORD, (LPBYTE)&needed, sizeof(DWORD) ) == ERROR_SUCCESS ) )
1301 {
1302 devprophdr.Flags &= ~DPS_NOPERMISSION;
1303 }
1304
1306
1307 res = (Ret >= 0);
1308
1309 if (!res)
1310 {
1311 FIXME("PrinterProperties fail ICPSUI\n");
1312 }
1313
1314 if (pi2) HeapFree(hProcessHeap, 0, pi2);
1315
1316 return res;
1317}
LONG WINAPI DevicePropertySheets(PPROPSHEETUI_INFO pCPSUIInfo, LPARAM lparam)
Definition: printers.c:1069
struct _DEVICEPROPERTYHEADER DEVICEPROPERTYHEADER
#define DPS_NOPERMISSION
Definition: winddiui.h:123
#define REG_DWORD
Definition: sdbapi.c:596
DWORD WINAPI SetPrinterDataW(HANDLE hPrinter, LPWSTR pValueName, DWORD Type, LPBYTE pData, DWORD cbData)

◆ QueryColorProfile()

BOOL WINAPI QueryColorProfile ( HANDLE  hPrinter,
PDEVMODEW  pdevmode,
ULONG  ulQueryMode,
VOID pvProfileData,
ULONG pcbProfileData,
FLONG pflProfileData 
)

Definition at line 2733 of file printers.c.

2740{
2741 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
2742 BOOL Ret = FALSE;
2744
2745 FIXME("QueryColorProfile(%p, %p, %l, %p, %p, %p)\n", hPrinter, pdevmode, ulQueryMode, pvProfileData, pcbProfileData, pflProfileData);
2746
2747 if ( pHandle->bNoColorProfile )
2748 {
2749 Ret = (BOOL)SP_ERROR;
2750 }
2751 else
2752 {
2753
2754 if ( pdevmode )
2755 {
2756 if (!IsValidDevmodeNoSizeW( pdevmode ) )
2757 {
2758 ERR("QueryColorProfile : Devode Invalid\n");
2759 return FALSE;
2760 }
2761 }
2762
2763 hLibrary = LoadPrinterDriver( hPrinter );
2764
2765 if ( hLibrary )
2766 {
2767 fpQueryColorProfile = (PVOID)GetProcAddress( hLibrary, "DrvQueryColorProfile" );
2768
2769 if ( fpQueryColorProfile )
2770 {
2771 Ret = fpQueryColorProfile( hPrinter, pdevmode, ulQueryMode, pvProfileData, pcbProfileData, pflProfileData );
2772 }
2773 else
2774 {
2775 pHandle->bNoColorProfile = TRUE;
2776 Ret = (BOOL)SP_ERROR;
2777 }
2778
2780 }
2781 }
2782 return Ret;
2783}
static QUERYCOLORPROFILE fpQueryColorProfile
Definition: printers.c:30
#define BOOL
Definition: nt_native.h:43
BOOL bNoColorProfile
Definition: precomp.h:46
#define SP_ERROR
Definition: wingdi.h:318

◆ QueryRemoteFonts()

DWORD WINAPI QueryRemoteFonts ( HANDLE  hPrinter,
PUNIVERSAL_FONT_ID  pufi,
ULONG  NumberOfUFIs 
)

Definition at line 2856 of file printers.c.

2857{
2858 HANDLE hIC;
2859 DWORD Result = -1, cOut, cIn = 0;
2860 PBYTE pOut;
2861
2862 FIXME("QueryRemoteFonts(%p, %p, %lu)\n", hPrinter, pufi, NumberOfUFIs);
2863
2864 hIC = CreatePrinterIC( hPrinter, NULL );
2865 if ( hIC )
2866 {
2867 cOut = (NumberOfUFIs * sizeof(UNIVERSAL_FONT_ID)) + sizeof(DWORD); // Include "DWORD" first part to return size.
2868
2869 pOut = HeapAlloc( hProcessHeap, 0, cOut );
2870 if ( pOut )
2871 {
2872 if ( PlayGdiScriptOnPrinterIC( hIC, (LPBYTE)&cIn, sizeof(DWORD), pOut, cOut, 0 ) )
2873 {
2874 cIn = *((PDWORD)pOut); // Fisrt part is the size of the UFID object.
2875
2876 Result = cIn; // Return the required size.
2877
2878 if( NumberOfUFIs < cIn )
2879 {
2880 cIn = NumberOfUFIs;
2881 }
2882 // Copy whole object back to GDI32, exclude first DWORD part.
2883 memcpy( pufi, pOut + sizeof(DWORD), cIn * sizeof(UNIVERSAL_FONT_ID) );
2884 }
2885 HeapFree( hProcessHeap, 0, pOut );
2886 }
2887 DeletePrinterIC( hIC );
2888 }
2889 return Result;
2890}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
struct _UNIVERSAL_FONT_ID UNIVERSAL_FONT_ID
DWORD * PDWORD
Definition: pedump.c:68
HANDLE WINAPI CreatePrinterIC(_In_ HANDLE hPrinter, _In_opt_ LPDEVMODEW pDevMode)
BOOL WINAPI PlayGdiScriptOnPrinterIC(_In_ HANDLE hPrinterIC, _In_reads_bytes_(cIn) LPBYTE pIn, _In_ DWORD cIn, _Out_writes_bytes_(cOut) LPBYTE pOut, _In_ DWORD cOut, _In_ DWORD ul)
BOOL WINAPI DeletePrinterIC(_In_ HANDLE hPrinterIC)

◆ QuerySpoolMode()

BOOL WINAPI QuerySpoolMode ( HANDLE  hPrinter,
PDWORD  downloadFontsFlags,
PDWORD  dwVersion 
)

Definition at line 2811 of file printers.c.

2812{
2813 PRINTER_INFO_2W *pi2 = NULL;
2814 DWORD needed = 0;
2815 BOOL res;
2816
2817 FIXME("QuerySpoolMode(%p, %p, %p)\n", hPrinter, downloadFontsFlags, dwVersion);
2818
2819 res = GetPrinterW( hPrinter, 2, NULL, 0, &needed);
2821 {
2822 pi2 = HeapAlloc(hProcessHeap, 0, needed);
2823 if (!pi2)
2824 {
2825 ERR("Failed to allocate PRINTER_INFO_2W of %u bytes\n", needed);
2826 return FALSE;
2827 }
2828 res = GetPrinterW(hPrinter, 2, (LPBYTE)pi2, needed, &needed);
2829 }
2830
2831 if ( res )
2832 {
2833 *dwVersion = 0x10000;
2834 *downloadFontsFlags = 0;
2835
2836 if ( pi2->pServerName )
2837 {
2838 *downloadFontsFlags |= QSM_DOWNLOADINGFONTS;
2839 }
2840 }
2841//
2842// Guessing,,,
2843// To do : Add GetPrinterDriver for DRIVER_INFO_8, test PRINTER_DRIVER_XPS flag,
2844// to set *downloadFontsFlags |= QSM_XPS_PASS;
2845//
2846// Vista+ looks for QSM_XPS_PASS to be set in GDI32.
2847//
2848 HeapFree(hProcessHeap, 0, pi2);
2849 return res;
2850}
#define QSM_DOWNLOADINGFONTS
Definition: printers.c:2793

◆ ReadPrinter()

BOOL WINAPI ReadPrinter ( HANDLE  hPrinter,
PVOID  pBuf,
DWORD  cbBuf,
PDWORD  pNoBytesRead 
)

Definition at line 2893 of file printers.c.

2894{
2895 DWORD dwErrorCode;
2896 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
2897
2898 TRACE("ReadPrinter(%p, %p, %lu, %p)\n", hPrinter, pBuf, cbBuf, pNoBytesRead);
2899
2900 // Sanity checks.
2901 if (!pHandle)
2902 {
2903 dwErrorCode = ERROR_INVALID_HANDLE;
2904 goto Cleanup;
2905 }
2906
2907 // Do the RPC call
2909 {
2910 dwErrorCode = _RpcReadPrinter(pHandle->hPrinter, pBuf, cbBuf, pNoBytesRead);
2911 }
2913 {
2914 dwErrorCode = RpcExceptionCode();
2915 ERR("_RpcReadPrinter failed with exception code %lu!\n", dwErrorCode);
2916 }
2918
2919Cleanup:
2920 SetLastError(dwErrorCode);
2921 return (dwErrorCode == ERROR_SUCCESS);
2922}
DWORD _RpcReadPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE *pBuf, DWORD cbBuf, DWORD *pcNoBytesRead)
Definition: printers.c:225

◆ ResetPrinterA()

BOOL WINAPI ResetPrinterA ( HANDLE  hPrinter,
PPRINTER_DEFAULTSA  pDefault 
)

Definition at line 2925 of file printers.c.

2926{
2927 BOOL ret;
2928 UNICODE_STRING pNameW;
2929 PDEVMODEW pdmw = NULL;
2930 PPRINTER_DEFAULTSW pdw = (PPRINTER_DEFAULTSW)pDefault;
2931
2932 TRACE("ResetPrinterA(%p, %p)\n", hPrinter, pDefault);
2933
2934 if ( pDefault->pDatatype == (LPSTR)-1 )
2935 {
2936 pdw->pDatatype = (LPWSTR)-1;
2937 }
2938 else
2939 {
2940 pdw->pDatatype = AsciiToUnicode( &pNameW, pDefault->pDatatype );
2941 }
2942 if ( pDefault->pDevMode == (LPDEVMODEA)-1)
2943 {
2944 pdw->pDevMode = (LPDEVMODEW)-1;
2945 }
2946 else
2947 {
2948 if ( pDefault->pDevMode )//&& IsValidDevmodeNoSizeW( pDefault->pDevMode ) )
2949 {
2951 pdw->pDevMode = pdmw;
2952 }
2953 }
2954
2955 ret = ResetPrinterW( hPrinter, pdw );
2956
2957 if (pdmw) HeapFree(hProcessHeap, 0, pdmw);
2958
2959 RtlFreeUnicodeString( &pNameW );
2960
2961 return ret;
2962}
struct _devicemodeW * LPDEVMODEW
WINBOOL WINAPI ResetPrinterW(HANDLE hPrinter, LPPRINTER_DEFAULTSW pDefault)
Definition: printers.c:2965
struct _PRINTER_DEFAULTSW * PPRINTER_DEFAULTSW
char * LPSTR
Definition: xmlstorage.h:182

◆ ResetPrinterW()

BOOL WINAPI ResetPrinterW ( HANDLE  hPrinter,
PPRINTER_DEFAULTSW  pDefault 
)

Definition at line 2965 of file printers.c.

2966{
2967 TRACE("ResetPrinterW(%p, %p)\n", hPrinter, pDefault);
2969 return FALSE;
2970}

Referenced by _RpcResetPrinterEx(), and ResetPrinterA().

◆ SeekPrinter()

BOOL WINAPI SeekPrinter ( HANDLE  hPrinter,
LARGE_INTEGER  liDistanceToMove,
PLARGE_INTEGER  pliNewPointer,
DWORD  dwMoveMethod,
BOOL  bWrite 
)

Definition at line 2973 of file printers.c.

2974{
2975 DWORD dwErrorCode;
2976 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
2977
2978 FIXME("SeekPrinter(%p, %I64u, %p, %lu, %d)\n", hPrinter, liDistanceToMove.QuadPart, pliNewPointer, dwMoveMethod, bWrite);
2979
2980 // Sanity checks.
2981 if (!pHandle)
2982 {
2983 dwErrorCode = ERROR_INVALID_HANDLE;
2984 goto Cleanup;
2985 }
2986
2987 // Do the RPC call
2989 {
2990 dwErrorCode = _RpcSeekPrinter(pHandle->hPrinter, liDistanceToMove, pliNewPointer, dwMoveMethod, bWrite);
2991 }
2993 {
2994 dwErrorCode = RpcExceptionCode();
2995 ERR("_RpcSeekPrinter failed with exception code %lu!\n", dwErrorCode);
2996 }
2998
2999Cleanup:
3000 SetLastError(dwErrorCode);
3001 return (dwErrorCode == ERROR_SUCCESS);
3002}
DWORD _RpcSeekPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER pliNewPointer, DWORD dwMoveMethod, BOOL bWrite)
Definition: printers.c:293
LONGLONG QuadPart
Definition: typedefs.h:114

◆ SetDefaultPrinterA()

BOOL WINAPI SetDefaultPrinterA ( LPCSTR  pszPrinter)

Definition at line 3005 of file printers.c.

3006{
3007 BOOL bReturnValue = FALSE;
3008 DWORD cch;
3009 PWSTR pwszPrinter = NULL;
3010
3011 TRACE("SetDefaultPrinterA(%s)\n", pszPrinter);
3012
3013 if (pszPrinter)
3014 {
3015 // Convert pszPrinter to a Unicode string pwszPrinter
3016 cch = strlen(pszPrinter);
3017
3018 pwszPrinter = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
3019 if (!pwszPrinter)
3020 {
3022 ERR("HeapAlloc failed!\n");
3023 goto Cleanup;
3024 }
3025
3026 MultiByteToWideChar(CP_ACP, 0, pszPrinter, -1, pwszPrinter, cch + 1);
3027 }
3028
3029 bReturnValue = SetDefaultPrinterW(pwszPrinter);
3030
3031Cleanup:
3032 if (pwszPrinter)
3033 HeapFree(hProcessHeap, 0, pwszPrinter);
3034
3035 return bReturnValue;
3036}
BOOL WINAPI SetDefaultPrinterW(LPCWSTR pszPrinter)
Definition: printers.c:3039

Referenced by START_TEST().

◆ SetDefaultPrinterW()

BOOL WINAPI SetDefaultPrinterW ( LPCWSTR  pszPrinter)

Definition at line 3039 of file printers.c.

3040{
3041 const WCHAR wszDevicesKey[] = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Devices";
3042
3043 DWORD cbDeviceValueData;
3044 DWORD cbPrinterValueData = 0;
3045 DWORD cchPrinter;
3046 DWORD dwErrorCode;
3047 HKEY hDevicesKey = NULL;
3048 HKEY hWindowsKey = NULL;
3049 PWSTR pwszDeviceValueData = NULL;
3050 WCHAR wszPrinter[MAX_PRINTER_NAME + 1];
3051
3052 TRACE("SetDefaultPrinterW(%S)\n", pszPrinter);
3053
3054 // Open the Devices registry key.
3055 dwErrorCode = (DWORD)RegOpenKeyExW(HKEY_CURRENT_USER, wszDevicesKey, 0, KEY_READ, &hDevicesKey);
3056 if (dwErrorCode != ERROR_SUCCESS)
3057 {
3058 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode);
3059 goto Cleanup;
3060 }
3061
3062 // Did the caller give us a printer to set as default?
3063 if (pszPrinter && *pszPrinter)
3064 {
3065 // Check if the given printer exists and query the value data size.
3066 dwErrorCode = (DWORD)RegQueryValueExW(hDevicesKey, pszPrinter, NULL, NULL, NULL, &cbPrinterValueData);
3067 if (dwErrorCode == ERROR_FILE_NOT_FOUND)
3068 {
3069 dwErrorCode = ERROR_INVALID_PRINTER_NAME;
3070 goto Cleanup;
3071 }
3072 else if (dwErrorCode != ERROR_SUCCESS)
3073 {
3074 ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode);
3075 goto Cleanup;
3076 }
3077
3078 cchPrinter = wcslen(pszPrinter);
3079 }
3080 else
3081 {
3082 // If there is already a default printer, we're done!
3083 cchPrinter = _countof(wszPrinter);
3084 if (GetDefaultPrinterW(wszPrinter, &cchPrinter))
3085 {
3086 dwErrorCode = ERROR_SUCCESS;
3087 goto Cleanup;
3088 }
3089
3090 // Otherwise, get us the first printer from the "Devices" key to later set it as default and query the value data size.
3091 cchPrinter = _countof(wszPrinter);
3092 dwErrorCode = (DWORD)RegEnumValueW(hDevicesKey, 0, wszPrinter, &cchPrinter, NULL, NULL, NULL, &cbPrinterValueData);
3093 if (dwErrorCode != ERROR_MORE_DATA)
3094 goto Cleanup;
3095
3096 pszPrinter = wszPrinter;
3097 }
3098
3099 // We now need to query the value data, which has the format "winspool,<Port>:"
3100 // and make "<Printer Name>,winspool,<Port>:" out of it.
3101 // Allocate a buffer large enough for the final data.
3102 cbDeviceValueData = (cchPrinter + 1) * sizeof(WCHAR) + cbPrinterValueData;
3103 pwszDeviceValueData = HeapAlloc(hProcessHeap, 0, cbDeviceValueData);
3104 if (!pwszDeviceValueData)
3105 {
3106 dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
3107 ERR("HeapAlloc failed!\n");
3108 goto Cleanup;
3109 }
3110
3111 // Copy the Printer Name and a comma into it.
3112 CopyMemory(pwszDeviceValueData, pszPrinter, cchPrinter * sizeof(WCHAR));
3113 pwszDeviceValueData[cchPrinter] = L',';
3114
3115 // Append the value data, which has the format "winspool,<Port>:"
3116 dwErrorCode = (DWORD)RegQueryValueExW(hDevicesKey, pszPrinter, NULL, NULL, (PBYTE)&pwszDeviceValueData[cchPrinter + 1], &cbPrinterValueData);
3117 if (dwErrorCode != ERROR_SUCCESS)
3118 goto Cleanup;
3119
3120 // Open the Windows registry key.
3121 dwErrorCode = (DWORD)RegOpenKeyExW(HKEY_CURRENT_USER, wszWindowsKey, 0, KEY_SET_VALUE, &hWindowsKey);
3122 if (dwErrorCode != ERROR_SUCCESS)
3123 {
3124 ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode);
3125 goto Cleanup;
3126 }
3127
3128 // Store our new default printer.
3129 dwErrorCode = (DWORD)RegSetValueExW(hWindowsKey, wszDeviceValue, 0, REG_SZ, (PBYTE)pwszDeviceValueData, cbDeviceValueData);
3130 if (dwErrorCode != ERROR_SUCCESS)
3131 {
3132 ERR("RegSetValueExW failed with status %lu!\n", dwErrorCode);
3133 goto Cleanup;
3134 }
3135
3136Cleanup:
3137 if (hDevicesKey)
3138 RegCloseKey(hDevicesKey);
3139
3140 if (hWindowsKey)
3141 RegCloseKey(hWindowsKey);
3142
3143 if (pwszDeviceValueData)
3144 HeapFree(hProcessHeap, 0, pwszDeviceValueData);
3145
3146 SetLastError(dwErrorCode);
3147 return (dwErrorCode == ERROR_SUCCESS);
3148}
#define ERROR_MORE_DATA
Definition: dderror.h:13
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
#define MAX_PRINTER_NAME
Definition: fpSetJob.c:25
#define REG_SZ
Definition: layer.c:22
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define _countof(array)
Definition: sndvol32.h:70
#define ERROR_INVALID_PRINTER_NAME
Definition: winerror.h:1108

Referenced by SetDefaultPrinterA(), and START_TEST().

◆ SetPrinterA()

BOOL WINAPI SetPrinterA ( HANDLE  hPrinter,
DWORD  Level,
PBYTE  pPrinter,
DWORD  Command 
)

Definition at line 3151 of file printers.c.

3152{
3153 BOOL Ret = FALSE;
3154 UNICODE_STRING usBuffer;
3157 PPRINTER_INFO_2A ppi2a = (PPRINTER_INFO_2A)pPrinter;
3158 PPRINTER_INFO_2W ppi2w = (PPRINTER_INFO_2W)pPrinter;
3159 PPRINTER_INFO_7A ppi7a = (PPRINTER_INFO_7A)pPrinter;
3160 PPRINTER_INFO_7W ppi7w = (PPRINTER_INFO_7W)pPrinter;
3161 PPRINTER_INFO_9A ppi9a = (PPRINTER_INFO_9A)pPrinter;
3162 PPRINTER_INFO_9W ppi9w = (PPRINTER_INFO_9W)pPrinter;
3163 PWSTR pwszPrinterName = NULL;
3164 PWSTR pwszServerName = NULL;
3165 PWSTR pwszShareName = NULL;
3166 PWSTR pwszPortName = NULL;
3167 PWSTR pwszDriverName = NULL;
3168 PWSTR pwszComment = NULL;
3169 PWSTR pwszLocation = NULL;
3170 PWSTR pwszSepFile = NULL;
3171 PWSTR pwszPrintProcessor = NULL;
3172 PWSTR pwszDatatype = NULL;
3173 PWSTR pwszParameters = NULL;
3174 PDEVMODEW pdmw = NULL;
3175
3176 FIXME("SetPrinterA(%p, %lu, %p, %lu)\n", hPrinter, Level, pPrinter, Command);
3177
3178 switch ( Level )
3179 {
3180 case 0:
3181 if ( Command == 0 )
3182 {
3183 if (ppisa->pPrinterName)
3184 {
3185 pwszPrinterName = AsciiToUnicode(&usBuffer, (LPCSTR)ppisa->pPrinterName);
3186 if (!(ppisw->pPrinterName = pwszPrinterName)) goto Cleanup;
3187 }
3188 if (ppisa->pServerName)
3189 {
3190 pwszServerName = AsciiToUnicode(&usBuffer, (LPCSTR)ppisa->pServerName);
3191 if (!(ppisw->pPrinterName = pwszServerName)) goto Cleanup;
3192 }
3193 }
3195 {
3196 // Set the pPrinter parameter to a pointer to a DWORD value that specifies the new printer status.
3197 PRINTER_INFO_6 pi6;
3198 pi6.dwStatus = (DWORD_PTR)pPrinter;
3199 pPrinter = (LPBYTE)&pi6;
3200 Level = 6;
3201 Command = 0;
3202 }
3203 break;
3204 case 2:
3205 {
3206 if (ppi2a->pShareName)
3207 {
3208 pwszShareName = AsciiToUnicode(&usBuffer, ppi2a->pShareName);
3209 if (!(ppi2w->pShareName = pwszShareName)) goto Cleanup;
3210 }
3211 if (ppi2a->pPortName)
3212 {
3213 pwszPortName = AsciiToUnicode(&usBuffer, ppi2a->pPortName);
3214 if (!(ppi2w->pPortName = pwszPortName)) goto Cleanup;
3215 }
3216 if (ppi2a->pDriverName)
3217 {
3218 pwszDriverName = AsciiToUnicode(&usBuffer, ppi2a->pDriverName);
3219 if (!(ppi2w->pDriverName = pwszDriverName)) goto Cleanup;
3220 }
3221 if (ppi2a->pComment)
3222 {
3223 pwszComment = AsciiToUnicode(&usBuffer, ppi2a->pComment);
3224 if (!(ppi2w->pComment = pwszComment)) goto Cleanup;
3225 }
3226 if (ppi2a->pLocation)
3227 {
3228 pwszLocation = AsciiToUnicode(&usBuffer, ppi2a->pLocation);
3229 if (!(ppi2w->pLocation = pwszLocation)) goto Cleanup;
3230 }
3231 if (ppi2a->pSepFile)
3232 {
3233 pwszSepFile = AsciiToUnicode(&usBuffer, ppi2a->pSepFile);
3234 if (!(ppi2w->pSepFile = pwszSepFile)) goto Cleanup;
3235 }
3236 if (ppi2a->pServerName)
3237 {
3238 pwszPrintProcessor = AsciiToUnicode(&usBuffer, ppi2a->pPrintProcessor);
3239 if (!(ppi2w->pPrintProcessor = pwszPrintProcessor)) goto Cleanup;
3240 }
3241 if (ppi2a->pDatatype)
3242 {
3243 pwszDatatype = AsciiToUnicode(&usBuffer, ppi2a->pDatatype);
3244 if (!(ppi2w->pDatatype = pwszDatatype)) goto Cleanup;
3245 }
3246 if (ppi2a->pParameters)
3247 {
3248 pwszParameters = AsciiToUnicode(&usBuffer, ppi2a->pParameters);
3249 if (!(ppi2w->pParameters = pwszParameters)) goto Cleanup;
3250 }
3251
3252 if ( ppi2a->pDevMode )
3253 {
3255 ppi2w->pDevMode = pdmw;
3256 }
3257 }
3258 //
3259 // These two strings are relitive and common to these three Levels.
3260 // Fall through...
3261 //
3262 case 4:
3263 case 5:
3264 {
3265 if (ppi2a->pServerName) // 4 & 5 : pPrinterName.
3266 {
3267 pwszServerName = AsciiToUnicode(&usBuffer, ppi2a->pServerName);
3268 if (!(ppi2w->pPrinterName = pwszServerName)) goto Cleanup;
3269 }
3270 if (ppi2a->pPrinterName) // 4 : pServerName, 5 : pPortName.
3271 {
3272 pwszPrinterName = AsciiToUnicode(&usBuffer, ppi2a->pPrinterName);
3273 if (!(ppi2w->pPrinterName = pwszPrinterName)) goto Cleanup;
3274 }
3275 }
3276 break;
3277 case 3:
3278 case 6:
3279 break;
3280 case 7:
3281 {
3282 if (ppi7a->pszObjectGUID)
3283 {
3284 pwszPrinterName = AsciiToUnicode(&usBuffer, ppi7a->pszObjectGUID);
3285 if (!(ppi7w->pszObjectGUID = pwszPrinterName)) goto Cleanup;
3286 }
3287 }
3288 break;
3289
3290 case 8:
3291 /* 8 is the global default printer info and 9 already sets it instead of the per-user one */
3292 /* still, PRINTER_INFO_8W is the same as PRINTER_INFO_9W */
3293 /* fall through */
3294 case 9:
3295 {
3297 ppi9w->pDevMode = pdmw;
3298 }
3299 break;
3300
3301 default:
3302 FIXME( "Unsupported level %d\n", Level);
3304 }
3305
3306 Ret = SetPrinterW( hPrinter, Level, pPrinter, Command );
3307
3308Cleanup:
3309 if (pdmw) HeapFree(hProcessHeap, 0, pdmw);
3310 if (pwszPrinterName) HeapFree(hProcessHeap, 0, pwszPrinterName);
3311 if (pwszServerName) HeapFree(hProcessHeap, 0, pwszServerName);
3312 if (pwszShareName) HeapFree(hProcessHeap, 0, pwszShareName);
3313 if (pwszPortName) HeapFree(hProcessHeap, 0, pwszPortName);
3314 if (pwszDriverName) HeapFree(hProcessHeap, 0, pwszDriverName);
3315 if (pwszComment) HeapFree(hProcessHeap, 0, pwszComment);
3316 if (pwszLocation) HeapFree(hProcessHeap, 0, pwszLocation);
3317 if (pwszSepFile) HeapFree(hProcessHeap, 0, pwszSepFile);
3318 if (pwszPrintProcessor) HeapFree(hProcessHeap, 0, pwszPrintProcessor);
3319 if (pwszDatatype) HeapFree(hProcessHeap, 0, pwszDatatype);
3320 if (pwszParameters) HeapFree(hProcessHeap, 0, pwszParameters);
3321 return Ret;
3322}
BOOL WINAPI SetPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pPrinter, DWORD Command)
Definition: printers.c:3325
struct _PRINTER_INFO_STRESS * PPRINTER_INFO_STRESS
Definition: shell.h:41
DWORD dwStatus
Definition: winspool.h:130
#define DWORD_PTR
Definition: treelist.c:76
#define PRINTER_CONTROL_SET_STATUS
Definition: winspool.h:180
const char * LPCSTR
Definition: xmlstorage.h:183

◆ SetPrinterW()

BOOL WINAPI SetPrinterW ( HANDLE  hPrinter,
DWORD  Level,
PBYTE  pPrinter,
DWORD  Command 
)

Definition at line 3325 of file printers.c.

3326{
3327 DWORD dwErrorCode;
3328 WINSPOOL_PRINTER_CONTAINER PrinterContainer;
3329 WINSPOOL_DEVMODE_CONTAINER DevModeContainer;
3330 WINSPOOL_SECURITY_CONTAINER SecurityContainer;
3332 DWORD size;
3333 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
3334
3335 FIXME("SetPrinterW(%p, %lu, %p, %lu)\n", hPrinter, Level, pPrinter, Command);
3336
3337 // Sanity checks
3338 if (!pHandle)
3339 return ERROR_INVALID_HANDLE;
3340
3341 DevModeContainer.cbBuf = 0;
3342 DevModeContainer.pDevMode = NULL;
3343
3344 SecurityContainer.cbBuf = 0;
3345 SecurityContainer.pSecurity = NULL;
3346
3347 switch ( Level )
3348 {
3349 case 0:
3351 {
3352 // Set the pPrinter parameter to a pointer to a DWORD value that specifies the new printer status.
3353 PRINTER_INFO_6 pi6;
3354 pi6.dwStatus = (DWORD_PTR)pPrinter;
3355 pPrinter = (LPBYTE)&pi6;
3356 Level = 6;
3357 Command = 0;
3358 }
3359 break;
3360 case 2:
3361 {
3362 PPRINTER_INFO_2W pi2w = (PPRINTER_INFO_2W)pPrinter;
3363 if ( pi2w )
3364 {
3365 if ( pi2w->pDevMode )
3366 {
3367 if ( IsValidDevmodeNoSizeW( pi2w->pDevMode ) )
3368 {
3369 DevModeContainer.cbBuf = pi2w->pDevMode->dmSize + pi2w->pDevMode->dmDriverExtra;
3370 DevModeContainer.pDevMode = (PBYTE)pi2w->pDevMode;
3371 }
3372 }
3373
3374 if ( pi2w->pSecurityDescriptor )
3375 {
3376 sd = get_sd( pi2w->pSecurityDescriptor, &size );
3377 if ( sd )
3378 {
3379 SecurityContainer.cbBuf = size;
3380 SecurityContainer.pSecurity = (PBYTE)sd;
3381 }
3382 }
3383 }
3384 else
3385 {
3387 return FALSE;
3388 }
3389 }
3390 break;
3391 case 3:
3392 {
3393 PPRINTER_INFO_3 pi3 = (PPRINTER_INFO_3)pPrinter;
3394 if ( pi3 )
3395 {
3396 if ( pi3->pSecurityDescriptor )
3397 {
3398 sd = get_sd( pi3->pSecurityDescriptor, &size );
3399 if ( sd )
3400 {
3401 SecurityContainer.cbBuf = size;
3402 SecurityContainer.pSecurity = (PBYTE)sd;
3403 }
3404 }
3405 }
3406 else
3407 {
3409 return FALSE;
3410 }
3411 }
3412 break;
3413
3414 case 4:
3415 case 5:
3416 case 6:
3417 case 7:
3418 if ( pPrinter == NULL )
3419 {
3421 return FALSE;
3422 }
3423 break;
3424
3425 case 8:
3426 /* 8 is the global default printer info and 9 already sets it instead of the per-user one */
3427 /* still, PRINTER_INFO_8W is the same as PRINTER_INFO_9W */
3428 /* fall through */
3429 case 9:
3430 {
3431 PPRINTER_INFO_9W pi9w = (PPRINTER_INFO_9W)pPrinter;
3432 if ( pi9w )
3433 {
3434 if ( pi9w->pDevMode )
3435 {
3436 if ( IsValidDevmodeNoSizeW( pi9w->pDevMode ) )
3437 {
3438 DevModeContainer.cbBuf = pi9w->pDevMode->dmSize + pi9w->pDevMode->dmDriverExtra;
3439 DevModeContainer.pDevMode = (LPBYTE)pi9w->pDevMode;
3440 }
3441 }
3442 }
3443 }
3444 break;
3445
3446 default:
3447 FIXME( "Unsupported level %d\n", Level );
3449 return FALSE;
3450 }
3451
3452 PrinterContainer.PrinterInfo.