ReactOS  0.4.15-dev-2144-g2282205
forms.c File Reference
#include "precomp.h"
#include <marshalling/forms.h>
Include dependency graph for forms.c:

Go to the source code of this file.

Functions

BOOL WINAPI AddFormA (HANDLE hPrinter, DWORD Level, PBYTE pForm)
 
BOOL WINAPI AddFormW (HANDLE hPrinter, DWORD Level, PBYTE pForm)
 
BOOL WINAPI DeleteFormA (HANDLE hPrinter, PSTR pFormName)
 
BOOL WINAPI DeleteFormW (HANDLE hPrinter, PWSTR pFormName)
 
BOOL WINAPI EnumFormsA (HANDLE hPrinter, DWORD Level, PBYTE pForm, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
 
BOOL WINAPI EnumFormsW (HANDLE hPrinter, DWORD Level, PBYTE pForm, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
 
BOOL WINAPI GetFormA (HANDLE hPrinter, PSTR pFormName, DWORD Level, PBYTE pForm, DWORD cbBuf, PDWORD pcbNeeded)
 
BOOL WINAPI GetFormW (HANDLE hPrinter, PWSTR pFormName, DWORD Level, PBYTE pForm, DWORD cbBuf, PDWORD pcbNeeded)
 
BOOL WINAPI SetFormA (HANDLE hPrinter, PSTR pFormName, DWORD Level, PBYTE pForm)
 
BOOL WINAPI SetFormW (HANDLE hPrinter, PWSTR pFormName, DWORD Level, PBYTE pForm)
 

Function Documentation

◆ AddFormA()

BOOL WINAPI AddFormA ( HANDLE  hPrinter,
DWORD  Level,
PBYTE  pForm 
)

Definition at line 12 of file forms.c.

13 {
14  FORM_INFO_2W pfi2W;
15  PFORM_INFO_2A pfi2A;
16  DWORD len;
17  BOOL res;
18 
19  pfi2A = (PFORM_INFO_2A)pForm;
20 
21  TRACE("AddFormA(%p, %lu, %p)\n", hPrinter, Level, pForm);
22 
23  if ((Level < 1) || (Level > 2))
24  {
25  ERR("Level = %d, unsupported!\n", Level);
27  return FALSE;
28  }
29 
30  if (!pfi2A)
31  {
33  return FALSE;
34  }
35 
36  ZeroMemory(&pfi2W, sizeof(FORM_INFO_2W));
37 
38  if (pfi2A->pName)
39  {
40  len = MultiByteToWideChar(CP_ACP, 0, pfi2A->pName, -1, NULL, 0);
41  pfi2W.pName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
42  MultiByteToWideChar(CP_ACP, 0, pfi2A->pName, -1, pfi2W.pName, len);
43  }
44 
45  pfi2W.Flags = pfi2A->Flags;
46  pfi2W.Size = pfi2A->Size;
47  pfi2W.ImageableArea = pfi2A->ImageableArea;
48 
49  if (Level > 1)
50  {
51  if (pfi2A->pKeyword)
52  {
53  len = MultiByteToWideChar(CP_ACP, 0, pfi2A->pKeyword, -1, NULL, 0);
54  pfi2W.pKeyword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
55  MultiByteToWideChar(CP_ACP, 0, pfi2A->pKeyword, -1, (LPWSTR)pfi2W.pKeyword, len);
56  }
57 
58  if (pfi2A->pMuiDll)
59  {
60  len = MultiByteToWideChar(CP_ACP, 0, pfi2A->pMuiDll, -1, NULL, 0);
61  pfi2W.pMuiDll = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
62  MultiByteToWideChar(CP_ACP, 0, pfi2A->pMuiDll, -1, (LPWSTR)pfi2W.pMuiDll, len);
63  }
64 
65  if (pfi2A->pDisplayName)
66  {
67  len = MultiByteToWideChar(CP_ACP, 0, pfi2A->pDisplayName, -1, NULL, 0);
68  pfi2W.pDisplayName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
70  }
71  pfi2W.StringType = pfi2A->StringType;
72  pfi2W.dwResourceId = pfi2A->dwResourceId;
73  pfi2W.wLangId = pfi2A->wLangId;
74  }
75 
76  res = AddFormW( hPrinter, Level, (PBYTE)&pfi2W );
77 
78  if (pfi2W.pName) HeapFree(GetProcessHeap(), 0, pfi2W.pName);
79  if (pfi2W.pKeyword) HeapFree(GetProcessHeap(), 0, (LPWSTR)pfi2W.pKeyword);
80  if (pfi2W.pMuiDll) HeapFree(GetProcessHeap(), 0, (LPWSTR)pfi2W.pMuiDll);
81  if (pfi2W.pDisplayName) HeapFree(GetProcessHeap(), 0, (LPWSTR)pfi2W.pDisplayName);
82 
83  return res;
84 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
DWORD dwResourceId
Definition: winspool.h:651
RECTL ImageableArea
Definition: winspool.h:660
DWORD StringType
Definition: winspool.h:649
#define CP_ACP
Definition: compat.h:109
LPWSTR pName
Definition: winspool.h:658
struct _FORM_INFO_2A * PFORM_INFO_2A
DWORD Flags
Definition: winspool.h:644
LANGID wLangId
Definition: winspool.h:666
#define ZeroMemory
Definition: winbase.h:1664
LPCWSTR pMuiDll
Definition: winspool.h:663
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
RECTL ImageableArea
Definition: winspool.h:647
LPCWSTR pDisplayName
Definition: winspool.h:665
LPSTR pName
Definition: winspool.h:645
BOOL WINAPI AddFormW(HANDLE hPrinter, DWORD Level, PBYTE pForm)
Definition: forms.c:11
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
SIZEL Size
Definition: winspool.h:646
#define TRACE(s)
Definition: solgame.cpp:4
DWORD dwResourceId
Definition: winspool.h:664
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
LANGID wLangId
Definition: winspool.h:653
#define SetLastError(x)
Definition: compat.h:611
LPCSTR pKeyword
Definition: winspool.h:661
GLenum GLsizei len
Definition: glext.h:6722
#define ERR(fmt,...)
Definition: debug.h:110
SIZEL Size
Definition: winspool.h:659
LPCSTR pDisplayName
Definition: winspool.h:652
DWORD StringType
Definition: winspool.h:662
#define NULL
Definition: types.h:112
LPCSTR pMuiDll
Definition: winspool.h:650
#define MultiByteToWideChar
Definition: compat.h:110
GLuint res
Definition: glext.h:9613
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
WCHAR * LPWSTR
Definition: xmlstorage.h:184
DWORD Flags
Definition: winspool.h:657
LPCSTR pKeyword
Definition: winspool.h:648
BYTE * PBYTE
Definition: pedump.c:66
#define HeapFree(x, y, z)
Definition: compat.h:594

◆ AddFormW()

BOOL WINAPI AddFormW ( HANDLE  hPrinter,
DWORD  Level,
PBYTE  pForm 
)

Definition at line 87 of file forms.c.

88 {
89  DWORD dwErrorCode;
90  WINSPOOL_FORM_CONTAINER FormInfoContainer;
91  PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
92 
93  TRACE("AddFormW(%p, %lu, %p)\n", hPrinter, Level, pForm);
94 
95  // Sanity checks.
96  if (!pHandle)
97  {
98  dwErrorCode = ERROR_INVALID_HANDLE;
99  return FALSE;
100  }
101 
102  if ((Level < 1) || (Level > 2))
103  {
104  ERR("Level = %d, unsupported!\n", Level);
106  return FALSE;
107  }
108 
109  FormInfoContainer.FormInfo.pFormInfo1 = (WINSPOOL_FORM_INFO_1*)pForm;
110  FormInfoContainer.Level = Level;
111 
112  // Do the RPC call
114  {
115  dwErrorCode = _RpcAddForm(pHandle->hPrinter, &FormInfoContainer);
116  }
118  {
119  dwErrorCode = RpcExceptionCode();
120  ERR("_RpcAddForm failed with exception code %lu!\n", dwErrorCode);
121  }
122  RpcEndExcept;
123 
124  SetLastError(dwErrorCode);
125  return (dwErrorCode == ERROR_SUCCESS);
126 }
#define RpcEndExcept
Definition: rpc.h:128
#define ERROR_SUCCESS
Definition: deptool.c:10
WINSPOOL_FORM_INFO_1 * pFormInfo1
Definition: winspool.idl:620
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
#define FALSE
Definition: types.h:117
#define RpcTryExcept
Definition: rpc.h:126
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
DWORD _RpcAddForm(WINSPOOL_PRINTER_HANDLE hPrinter, WINSPOOL_FORM_CONTAINER *pFormInfoContainer)
Definition: forms.c:12
#define RpcExceptionCode()
Definition: rpc.h:132
#define TRACE(s)
Definition: solgame.cpp:4
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
#define ERR(fmt,...)
Definition: debug.h:110
union _WINSPOOL_FORM_CONTAINER::@3382 FormInfo
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
struct _SPOOLER_HANDLE * PSPOOLER_HANDLE
#define RpcExcept(expr)
Definition: rpc.h:127
HANDLE hPrinter
Definition: precomp.h:50

◆ DeleteFormA()

BOOL WINAPI DeleteFormA ( HANDLE  hPrinter,
PSTR  pFormName 
)

Definition at line 129 of file forms.c.

130 {
131  UNICODE_STRING FormNameW;
132  BOOL Ret;
133 
134  TRACE("DeleteFormA(%p, %s)\n", hPrinter, pFormName);
135 
136  AsciiToUnicode(&FormNameW, pFormName);
137 
138  Ret = DeleteFormW( hPrinter, FormNameW.Buffer );
139 
140  RtlFreeUnicodeString(&FormNameW);
141 
142  return Ret;
143 }
unsigned int BOOL
Definition: ntddk_ex.h:94
wstring AsciiToUnicode(const char *AsciiString)
Definition: tools.cpp:220
#define TRACE(s)
Definition: solgame.cpp:4
BOOL WINAPI DeleteFormW(HANDLE hPrinter, PWSTR pFormName)
Definition: forms.c:26
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)

◆ DeleteFormW()

BOOL WINAPI DeleteFormW ( HANDLE  hPrinter,
PWSTR  pFormName 
)

Definition at line 146 of file forms.c.

147 {
148  DWORD dwErrorCode;
149  PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
150 
151  TRACE("DeleteFormW(%p, %S)\n", hPrinter, pFormName);
152 
153  // Sanity checks.
154  if (!pHandle)
155  {
156  dwErrorCode = ERROR_INVALID_HANDLE;
157  return FALSE;
158  }
159 
160  // Do the RPC call
162  {
163  dwErrorCode = _RpcDeleteForm(pHandle->hPrinter, pFormName);
164  }
166  {
167  dwErrorCode = RpcExceptionCode();
168  ERR("_RpcDeleteForm failed with exception code %lu!\n", dwErrorCode);
169  }
170  RpcEndExcept;
171 
172  SetLastError(dwErrorCode);
173  return (dwErrorCode == ERROR_SUCCESS);
174 }
#define RpcEndExcept
Definition: rpc.h:128
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
DWORD _RpcDeleteForm(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR *pFormName)
Definition: forms.c:31
#define FALSE
Definition: types.h:117
#define RpcTryExcept
Definition: rpc.h:126
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define RpcExceptionCode()
Definition: rpc.h:132
#define TRACE(s)
Definition: solgame.cpp:4
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
#define ERR(fmt,...)
Definition: debug.h:110
struct _SPOOLER_HANDLE * PSPOOLER_HANDLE
#define RpcExcept(expr)
Definition: rpc.h:127
HANDLE hPrinter
Definition: precomp.h:50

◆ EnumFormsA()

BOOL WINAPI EnumFormsA ( HANDLE  hPrinter,
DWORD  Level,
PBYTE  pForm,
DWORD  cbBuf,
PDWORD  pcbNeeded,
PDWORD  pcReturned 
)

Definition at line 177 of file forms.c.

178 {
179  DWORD dwErrorCode, i;
180  PFORM_INFO_1W pfi1w = (PFORM_INFO_1W)pForm;
181  PFORM_INFO_2W pfi2w = (PFORM_INFO_2W)pForm;
182 
183  TRACE("EnumFormsA(%p, %lu, %p, %lu, %p, %p)\n", hPrinter, Level, pForm, cbBuf, pcbNeeded, pcReturned);
184 
185  if ( EnumFormsW( hPrinter, Level, pForm, cbBuf, pcbNeeded, pcReturned ) )
186  {
187  for ( i = 0; i < *pcReturned; i++ )
188  {
189  switch ( Level )
190  {
191  case 2:
192  dwErrorCode = UnicodeToAnsiInPlace((LPWSTR)pfi2w[i].pKeyword);
193  if (dwErrorCode != ERROR_SUCCESS)
194  {
195  goto Cleanup;
196  }
197  dwErrorCode = UnicodeToAnsiInPlace((LPWSTR)pfi2w[i].pMuiDll);
198  if (dwErrorCode != ERROR_SUCCESS)
199  {
200  goto Cleanup;
201  }
202  dwErrorCode = UnicodeToAnsiInPlace((LPWSTR)pfi2w[i].pDisplayName);
203  if (dwErrorCode != ERROR_SUCCESS)
204  {
205  goto Cleanup;
206  }
207  dwErrorCode = UnicodeToAnsiInPlace(pfi2w[i].pName);
208  if (dwErrorCode != ERROR_SUCCESS)
209  {
210  goto Cleanup;
211  }
212  break;
213  case 1:
214  dwErrorCode = UnicodeToAnsiInPlace(pfi1w[i].pName);
215  if (dwErrorCode != ERROR_SUCCESS)
216  {
217  goto Cleanup;
218  }
219  }
220  }
221  return TRUE;
222  }
223 Cleanup:
224  return FALSE;
225 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
#define FALSE
Definition: types.h:117
#define TRACE(s)
Definition: solgame.cpp:4
static LPSTR pName
Definition: security.c:75
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD UnicodeToAnsiInPlace(PWSTR pwszField)
Definition: utils.c:26
static const WCHAR Cleanup[]
Definition: register.c:80
struct _FORM_INFO_1W * PFORM_INFO_1W
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
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
BOOL WINAPI EnumFormsW(HANDLE hPrinter, DWORD Level, PBYTE pForm, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: forms.c:41
struct _FORM_INFO_2W * PFORM_INFO_2W
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ EnumFormsW()

BOOL WINAPI EnumFormsW ( HANDLE  hPrinter,
DWORD  Level,
PBYTE  pForm,
DWORD  cbBuf,
PDWORD  pcbNeeded,
PDWORD  pcReturned 
)

Definition at line 228 of file forms.c.

229 {
230  DWORD dwErrorCode;
231  PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
232 
233  TRACE("EnumFormsW(%p, %lu, %p, %lu, %p, %p)\n", hPrinter, Level, pForm, cbBuf, pcbNeeded, pcReturned);
234 
235  // Sanity checks.
236  if (!pHandle)
237  {
238  dwErrorCode = ERROR_INVALID_HANDLE;
239  goto Cleanup;
240  }
241 
242  if ((Level < 1) || (Level > 2))
243  {
244  ERR("Level = %d, unsupported!\n", Level);
245  dwErrorCode = ERROR_INVALID_LEVEL;
246  goto Cleanup;
247  }
248 
249  // Do the RPC call
251  {
252  dwErrorCode = _RpcEnumForms(pHandle->hPrinter, Level, pForm, cbBuf, pcbNeeded, pcReturned);
253  }
255  {
256  dwErrorCode = RpcExceptionCode();
257  ERR("_RpcEnumForms failed with exception code %lu!\n", dwErrorCode);
258  }
259  RpcEndExcept;
260 
261  if (dwErrorCode == ERROR_SUCCESS)
262  {
263  // Replace relative offset addresses in the output by absolute pointers.
264  ASSERT(Level >= 1 && Level <= 2);
265  MarshallUpStructuresArray(cbBuf, pForm, *pcReturned, pFormInfoMarshalling[Level]->pInfo, pFormInfoMarshalling[Level]->cbStructureSize, TRUE);
266  }
267 
268 Cleanup:
269  SetLastError(dwErrorCode);
270  return (dwErrorCode == ERROR_SUCCESS);
271 }
#define RpcEndExcept
Definition: rpc.h:128
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
#define RpcTryExcept
Definition: rpc.h:126
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define RpcExceptionCode()
Definition: rpc.h:132
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:45
DWORD _RpcEnumForms(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD Level, BYTE *pForm, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
Definition: forms.c:50
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
static const WCHAR Cleanup[]
Definition: register.c:80
static const MARSHALLING * pFormInfoMarshalling[]
Definition: forms.h:36
#define ERR(fmt,...)
Definition: debug.h:110
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
struct _SPOOLER_HANDLE * PSPOOLER_HANDLE
#define RpcExcept(expr)
Definition: rpc.h:127
BOOL WINAPI MarshallUpStructuresArray(DWORD cbSize, PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:202
HANDLE hPrinter
Definition: precomp.h:50

◆ GetFormA()

BOOL WINAPI GetFormA ( HANDLE  hPrinter,
PSTR  pFormName,
DWORD  Level,
PBYTE  pForm,
DWORD  cbBuf,
PDWORD  pcbNeeded 
)

Definition at line 274 of file forms.c.

275 {
276  DWORD dwErrorCode, len;
277  LPWSTR FormNameW = NULL;
278  PFORM_INFO_1W pfi1w = (PFORM_INFO_1W)pForm;
279  PFORM_INFO_2W pfi2w = (PFORM_INFO_2W)pForm;
280 
281  TRACE("GetFormA(%p, %s, %lu, %p, %lu, %p)\n", hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded);
282 
283  if (pFormName)
284  {
285  len = MultiByteToWideChar(CP_ACP, 0, pFormName, -1, NULL, 0);
286  FormNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
287  MultiByteToWideChar(CP_ACP, 0, pFormName, -1, FormNameW, len);
288  }
289 
290  if ( GetFormW( hPrinter, FormNameW, Level, pForm, cbBuf, pcbNeeded ) )
291  {
292  switch ( Level )
293  {
294  case 2:
295  dwErrorCode = UnicodeToAnsiInPlace((LPWSTR)pfi2w->pKeyword);
296  if (dwErrorCode != ERROR_SUCCESS)
297  {
298  goto Cleanup;
299  }
300  dwErrorCode = UnicodeToAnsiInPlace((LPWSTR)pfi2w->pMuiDll);
301  if (dwErrorCode != ERROR_SUCCESS)
302  {
303  goto Cleanup;
304  }
305  dwErrorCode = UnicodeToAnsiInPlace((LPWSTR)pfi2w->pDisplayName);
306  if (dwErrorCode != ERROR_SUCCESS)
307  {
308  goto Cleanup;
309  }
310  dwErrorCode = UnicodeToAnsiInPlace(pfi2w->pName);
311  if (dwErrorCode != ERROR_SUCCESS)
312  {
313  goto Cleanup;
314  }
315  break;
316  case 1:
317  dwErrorCode = UnicodeToAnsiInPlace(pfi1w->pName);
318  if (dwErrorCode != ERROR_SUCCESS)
319  {
320  goto Cleanup;
321  }
322  }
323  }
324 Cleanup:
325  if (FormNameW) HeapFree(GetProcessHeap(), 0, FormNameW);
326  return (dwErrorCode == ERROR_SUCCESS);
327 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define CP_ACP
Definition: compat.h:109
LPWSTR pName
Definition: winspool.h:658
LPCWSTR pMuiDll
Definition: winspool.h:663
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
LPCWSTR pDisplayName
Definition: winspool.h:665
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
LPCSTR pKeyword
Definition: winspool.h:661
DWORD UnicodeToAnsiInPlace(PWSTR pwszField)
Definition: utils.c:26
GLenum GLsizei len
Definition: glext.h:6722
static const WCHAR Cleanup[]
Definition: register.c:80
struct _FORM_INFO_1W * PFORM_INFO_1W
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
LPWSTR pName
Definition: winspool.h:634
#define NULL
Definition: types.h:112
#define MultiByteToWideChar
Definition: compat.h:110
struct _FORM_INFO_2W * PFORM_INFO_2W
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:594
BOOL WINAPI GetFormW(HANDLE hPrinter, PWSTR pFormName, DWORD Level, PBYTE pForm, DWORD cbBuf, PDWORD pcbNeeded)
Definition: forms.c:62

◆ GetFormW()

BOOL WINAPI GetFormW ( HANDLE  hPrinter,
PWSTR  pFormName,
DWORD  Level,
PBYTE  pForm,
DWORD  cbBuf,
PDWORD  pcbNeeded 
)

Definition at line 330 of file forms.c.

331 {
332  DWORD dwErrorCode;
333  PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
334 
335  TRACE("GetFormW(%p, %S, %lu, %p, %lu, %p)\n", hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded);
336 
337  // Sanity checks.
338  if (!pHandle)
339  {
340  dwErrorCode = ERROR_INVALID_HANDLE;
341  goto Cleanup;
342  }
343 
344  // Dismiss invalid levels already at this point.
345  if ((Level < 1) || (Level > 2))
346  {
347  ERR("Level = %d, unsupported!\n", Level);
348  dwErrorCode = ERROR_INVALID_LEVEL;
349  goto Cleanup;
350  }
351 
352  if (cbBuf && pForm)
353  ZeroMemory(pForm, cbBuf);
354 
355  // Do the RPC call
357  {
358  dwErrorCode = _RpcGetForm(pHandle->hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded);
359  }
361  {
362  dwErrorCode = RpcExceptionCode();
363  ERR("_RpcGetForm failed with exception code %lu!\n", dwErrorCode);
364  }
365  RpcEndExcept;
366 
367  if (dwErrorCode == ERROR_SUCCESS)
368  {
369  // Replace relative offset addresses in the output by absolute pointers.
370  ASSERT(Level >= 1 && Level <= 2);
371  MarshallUpStructure(cbBuf, pForm, pFormInfoMarshalling[Level]->pInfo, pFormInfoMarshalling[Level]->cbStructureSize, TRUE);
372  }
373 
374 Cleanup:
375  SetLastError(dwErrorCode);
376  return (dwErrorCode == ERROR_SUCCESS);
377 }
#define RpcEndExcept
Definition: rpc.h:128
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define ZeroMemory
Definition: winbase.h:1664
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
#define RpcTryExcept
Definition: rpc.h:126
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define RpcExceptionCode()
Definition: rpc.h:132
#define TRACE(s)
Definition: solgame.cpp:4
#define ASSERT(a)
Definition: mode.c:45
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
static const WCHAR Cleanup[]
Definition: register.c:80
BOOL WINAPI MarshallUpStructure(DWORD cbSize, PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:137
static const MARSHALLING * pFormInfoMarshalling[]
Definition: forms.h:36
#define ERR(fmt,...)
Definition: debug.h:110
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
struct _SPOOLER_HANDLE * PSPOOLER_HANDLE
DWORD _RpcGetForm(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR *pFormName, DWORD Level, BYTE *pForm, DWORD cbBuf, DWORD *pcbNeeded)
Definition: forms.c:82
#define RpcExcept(expr)
Definition: rpc.h:127
HANDLE hPrinter
Definition: precomp.h:50

◆ SetFormA()

BOOL WINAPI SetFormA ( HANDLE  hPrinter,
PSTR  pFormName,
DWORD  Level,
PBYTE  pForm 
)

Definition at line 380 of file forms.c.

381 {
382  FORM_INFO_2W pfi2W;
383  FORM_INFO_2A * pfi2A;
384  LPWSTR FormNameW = NULL;
385  DWORD len;
386  BOOL res;
387 
388  pfi2A = (FORM_INFO_2A *) pForm;
389 
390  TRACE("SetFormA(%p, %s, %lu, %p)\n", hPrinter, pFormName, Level, pForm);
391 
392  if ((Level < 1) || (Level > 2))
393  {
394  ERR("Level = %d, unsupported!\n", Level);
396  return FALSE;
397  }
398 
399  if (!pfi2A)
400  {
402  return FALSE;
403  }
404 
405  if (pFormName)
406  {
407  len = MultiByteToWideChar(CP_ACP, 0, pFormName, -1, NULL, 0);
408  FormNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
409  MultiByteToWideChar(CP_ACP, 0, pFormName, -1, FormNameW, len);
410  }
411 
412  ZeroMemory(&pfi2W, sizeof(FORM_INFO_2W));
413 
414  if (pfi2A->pName)
415  {
416  len = MultiByteToWideChar(CP_ACP, 0, pfi2A->pName, -1, NULL, 0);
417  pfi2W.pName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
418  MultiByteToWideChar(CP_ACP, 0, pfi2A->pName, -1, pfi2W.pName, len);
419  }
420 
421  pfi2W.Flags = pfi2A->Flags;
422  pfi2W.Size = pfi2A->Size;
423  pfi2W.ImageableArea = pfi2A->ImageableArea;
424 
425  if (Level > 1)
426  {
427  if (pfi2A->pKeyword)
428  {
429  len = MultiByteToWideChar(CP_ACP, 0, pfi2A->pKeyword, -1, NULL, 0);
430  pfi2W.pKeyword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
431  MultiByteToWideChar(CP_ACP, 0, pfi2A->pKeyword, -1, (LPWSTR)pfi2W.pKeyword, len);
432  }
433 
434  if (pfi2A->pMuiDll)
435  {
436  len = MultiByteToWideChar(CP_ACP, 0, pfi2A->pMuiDll, -1, NULL, 0);
437  pfi2W.pMuiDll = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
438  MultiByteToWideChar(CP_ACP, 0, pfi2A->pMuiDll, -1, (LPWSTR)pfi2W.pMuiDll, len);
439  }
440 
441  if (pfi2A->pDisplayName)
442  {
443  len = MultiByteToWideChar(CP_ACP, 0, pfi2A->pDisplayName, -1, NULL, 0);
444  pfi2W.pDisplayName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
446  }
447  pfi2W.StringType = pfi2A->StringType;
448  pfi2W.dwResourceId = pfi2A->dwResourceId;
449  pfi2W.wLangId = pfi2A->wLangId;
450  }
451 
452  res = SetFormW( hPrinter, FormNameW, Level, (PBYTE)&pfi2W );
453 
454  if (FormNameW) HeapFree(GetProcessHeap(), 0, FormNameW);
455  if (pfi2W.pName) HeapFree(GetProcessHeap(), 0, pfi2W.pName);
456  if (pfi2W.pKeyword) HeapFree(GetProcessHeap(), 0, (LPWSTR)pfi2W.pKeyword);
457  if (pfi2W.pMuiDll) HeapFree(GetProcessHeap(), 0, (LPWSTR)pfi2W.pMuiDll);
458  if (pfi2W.pDisplayName) HeapFree(GetProcessHeap(), 0, (LPWSTR)pfi2W.pDisplayName);
459 
460  return res;
461 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
DWORD dwResourceId
Definition: winspool.h:651
RECTL ImageableArea
Definition: winspool.h:660
DWORD StringType
Definition: winspool.h:649
#define CP_ACP
Definition: compat.h:109
LPWSTR pName
Definition: winspool.h:658
DWORD Flags
Definition: winspool.h:644
LANGID wLangId
Definition: winspool.h:666
#define ZeroMemory
Definition: winbase.h:1664
LPCWSTR pMuiDll
Definition: winspool.h:663
BOOL WINAPI SetFormW(HANDLE hPrinter, PWSTR pFormName, DWORD Level, PBYTE pForm)
Definition: forms.c:83
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
RECTL ImageableArea
Definition: winspool.h:647
LPCWSTR pDisplayName
Definition: winspool.h:665
LPSTR pName
Definition: winspool.h:645
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
SIZEL Size
Definition: winspool.h:646
#define TRACE(s)
Definition: solgame.cpp:4
DWORD dwResourceId
Definition: winspool.h:664
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
LANGID wLangId
Definition: winspool.h:653
#define SetLastError(x)
Definition: compat.h:611
LPCSTR pKeyword
Definition: winspool.h:661
GLenum GLsizei len
Definition: glext.h:6722
#define ERR(fmt,...)
Definition: debug.h:110
SIZEL Size
Definition: winspool.h:659
LPCSTR pDisplayName
Definition: winspool.h:652
DWORD StringType
Definition: winspool.h:662
#define NULL
Definition: types.h:112
LPCSTR pMuiDll
Definition: winspool.h:650
#define MultiByteToWideChar
Definition: compat.h:110
GLuint res
Definition: glext.h:9613
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
WCHAR * LPWSTR
Definition: xmlstorage.h:184
DWORD Flags
Definition: winspool.h:657
LPCSTR pKeyword
Definition: winspool.h:648
BYTE * PBYTE
Definition: pedump.c:66
#define HeapFree(x, y, z)
Definition: compat.h:594

◆ SetFormW()

BOOL WINAPI SetFormW ( HANDLE  hPrinter,
PWSTR  pFormName,
DWORD  Level,
PBYTE  pForm 
)

Definition at line 464 of file forms.c.

465 {
466  DWORD dwErrorCode;
467  WINSPOOL_FORM_CONTAINER FormInfoContainer;
468  PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
469 
470  TRACE("SetFormW(%p, %S, %lu, %p)\n", hPrinter, pFormName, Level, pForm);
471 
472  // Sanity checks.
473  if (!pHandle)
474  {
475  ERR("Level = %d, unsupported!\n", Level);
476  dwErrorCode = ERROR_INVALID_HANDLE;
477  return FALSE;
478  }
479 
480  FormInfoContainer.FormInfo.pFormInfo1 = (WINSPOOL_FORM_INFO_1*)pForm;
481  FormInfoContainer.Level = Level;
482 
483  // Do the RPC call
485  {
486  dwErrorCode = _RpcSetForm(pHandle->hPrinter, pFormName, &FormInfoContainer);
487  }
489  {
490  dwErrorCode = RpcExceptionCode();
491  }
492  RpcEndExcept;
493 
494  SetLastError(dwErrorCode);
495  return (dwErrorCode == ERROR_SUCCESS);
496 }
#define RpcEndExcept
Definition: rpc.h:128
#define ERROR_SUCCESS
Definition: deptool.c:10
WINSPOOL_FORM_INFO_1 * pFormInfo1
Definition: winspool.idl:620
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
DWORD _RpcSetForm(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR *pFormName, WINSPOOL_FORM_CONTAINER *pFormInfoContainer)
Definition: forms.c:114
#define FALSE
Definition: types.h:117
#define RpcTryExcept
Definition: rpc.h:126
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define RpcExceptionCode()
Definition: rpc.h:132
#define TRACE(s)
Definition: solgame.cpp:4
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
#define ERR(fmt,...)
Definition: debug.h:110
union _WINSPOOL_FORM_CONTAINER::@3382 FormInfo
struct _SPOOLER_HANDLE * PSPOOLER_HANDLE
#define RpcExcept(expr)
Definition: rpc.h:127
HANDLE hPrinter
Definition: precomp.h:50