ReactOS  0.4.14-dev-52-g6116262
printdlg.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "wingdi.h"
#include "winuser.h"
#include "objbase.h"
#include "cderr.h"
#include "commdlg.h"
#include "dlgs.h"
#include "winspool.h"
#include "wine/test.h"
Include dependency graph for printdlg.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 
#define CONST_VTABLE
 

Functions

static HRESULT (WINAPI *pPrintDlgExW)(LPPRINTDLGEXW)
 
static void test_PageSetupDlgA (void)
 
static UINT_PTR CALLBACK print_hook_proc (HWND hdlg, UINT msg, WPARAM wp, LPARAM lp)
 
static void test_PrintDlgA (void)
 
static HRESULT WINAPI callback_QueryInterface (IPrintDialogCallback *iface, REFIID riid, void **ppv)
 
static ULONG WINAPI callback_AddRef (IPrintDialogCallback *iface)
 
static ULONG WINAPI callback_Release (IPrintDialogCallback *iface)
 
static HRESULT WINAPI callback_InitDone (IPrintDialogCallback *iface)
 
static HRESULT WINAPI callback_SelectionChange (IPrintDialogCallback *iface)
 
static HRESULT WINAPI callback_HandleMessage (IPrintDialogCallback *iface, HWND hdlg, UINT msg, WPARAM wp, LPARAM lp, LRESULT *res)
 
static HRESULT WINAPI unknown_QueryInterface (IUnknown *iface, REFIID riid, void **ppv)
 
static ULONG WINAPI unknown_AddRef (IUnknown *iface)
 
static ULONG WINAPI unknown_Release (IUnknown *iface)
 
static void test_PrintDlgExW (void)
 
static BOOL CALLBACK abort_proc (HDC hdc, int error)
 
static void test_abort_proc (void)
 
 START_TEST (printdlg)
 

Variables

const IID IID_IObjectWithSite
 
static HMODULE hcomdlg32
 
static const CHAR emptyA [] = ""
 
static const CHAR PrinterPortsA [] = "PrinterPorts"
 
static const IPrintDialogCallbackVtbl callback_Vtbl
 
static IPrintDialogCallback callback = { &callback_Vtbl }
 
static const IUnknownVtbl unknown_Vtbl
 
static IUnknown unknown = { &unknown_Vtbl }
 
static BOOL abort_proc_called = FALSE
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 23 of file printdlg.c.

◆ CONST_VTABLE

#define CONST_VTABLE

Definition at line 24 of file printdlg.c.

Function Documentation

◆ abort_proc()

static BOOL CALLBACK abort_proc ( HDC  hdc,
int  error 
)
static

Definition at line 559 of file printdlg.c.

559 { return abort_proc_called = TRUE; }
#define TRUE
Definition: types.h:120
static BOOL abort_proc_called
Definition: printdlg.c:558

Referenced by test_abort_proc().

◆ callback_AddRef()

static ULONG WINAPI callback_AddRef ( IPrintDialogCallback *  iface)
static

Definition at line 284 of file printdlg.c.

285 {
286  trace("callback_AddRef\n");
287  return 2;
288 }
#define trace
Definition: atltest.h:70

◆ callback_HandleMessage()

static HRESULT WINAPI callback_HandleMessage ( IPrintDialogCallback *  iface,
HWND  hdlg,
UINT  msg,
WPARAM  wp,
LPARAM  lp,
LRESULT res 
)
static

Definition at line 308 of file printdlg.c.

310 {
311  trace("callback_HandleMessage %p,%04x,%lx,%lx,%p\n", hdlg, msg, wp, lp, res);
312  /* *res = PD_RESULT_PRINT; */
313  return S_OK;
314 }
#define trace
Definition: atltest.h:70
#define S_OK
Definition: intsafe.h:59
#define msg(x)
Definition: auth_time.c:54
GLuint res
Definition: glext.h:9613

◆ callback_InitDone()

static HRESULT WINAPI callback_InitDone ( IPrintDialogCallback *  iface)
static

Definition at line 296 of file printdlg.c.

297 {
298  trace("callback_InitDone\n");
299  return S_OK;
300 }
#define trace
Definition: atltest.h:70
#define S_OK
Definition: intsafe.h:59

◆ callback_QueryInterface()

static HRESULT WINAPI callback_QueryInterface ( IPrintDialogCallback *  iface,
REFIID  riid,
void **  ppv 
)
static

Definition at line 277 of file printdlg.c.

279 {
280  ok(0, "callback_QueryInterface(%s): unexpected call\n", wine_dbgstr_guid(riid));
281  return E_NOINTERFACE;
282 }
#define E_NOINTERFACE
Definition: winerror.h:2364
REFIID riid
Definition: precomp.h:44
const char * wine_dbgstr_guid(const GUID *guid)
#define ok(value,...)
Definition: atltest.h:57

◆ callback_Release()

static ULONG WINAPI callback_Release ( IPrintDialogCallback *  iface)
static

Definition at line 290 of file printdlg.c.

291 {
292  trace("callback_Release\n");
293  return 1;
294 }
#define trace
Definition: atltest.h:70

◆ callback_SelectionChange()

static HRESULT WINAPI callback_SelectionChange ( IPrintDialogCallback *  iface)
static

Definition at line 302 of file printdlg.c.

303 {
304  trace("callback_SelectionChange\n");
305  return S_OK;
306 }
#define trace
Definition: atltest.h:70
#define S_OK
Definition: intsafe.h:59

◆ HRESULT()

static HRESULT ( WINAPI pPrintDlgExW)
static

◆ print_hook_proc()

static UINT_PTR CALLBACK print_hook_proc ( HWND  hdlg,
UINT  msg,
WPARAM  wp,
LPARAM  lp 
)
static

Definition at line 117 of file printdlg.c.

118 {
119  if (msg == WM_INITDIALOG)
120  {
121  /* some driver popup a dialog and hung the test or silently limit the number of copies,
122  when trying to set more than 999 copies */
123  SetDlgItemInt(hdlg, edt3, 123, FALSE);
125  }
126  return 0;
127 }
#define IDOK
Definition: winuser.h:824
BOOL WINAPI PostMessageA(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI SetDlgItemInt(_In_ HWND, _In_ int, _In_ UINT, _In_ BOOL)
#define WM_COMMAND
Definition: winuser.h:1722
#define msg(x)
Definition: auth_time.c:54
#define edt3
Definition: dlgs.h:67
#define WM_INITDIALOG
Definition: winuser.h:1721

Referenced by test_PrintDlgA().

◆ START_TEST()

START_TEST ( printdlg  )

Definition at line 638 of file printdlg.c.

639 {
640  hcomdlg32 = GetModuleHandleA("comdlg32.dll");
641  pPrintDlgExW = (void *) GetProcAddress(hcomdlg32, "PrintDlgExW");
642 
644  test_PrintDlgA();
646  test_abort_proc();
647 }
static void test_PageSetupDlgA(void)
Definition: printdlg.c:57
static void test_PrintDlgExW(void)
Definition: printdlg.c:369
static HMODULE hcomdlg32
Definition: printdlg.c:47
static void test_PrintDlgA(void)
Definition: printdlg.c:129
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
#define GetProcAddress(x, y)
Definition: compat.h:410
static void test_abort_proc(void)
Definition: printdlg.c:560

◆ test_abort_proc()

static void test_abort_proc ( void  )
static

Definition at line 560 of file printdlg.c.

561 {
562  HDC print_dc;
563  RECT rect = {0, 0, 100, 100};
564  DOCINFOA doc_info = {0};
565  PRINTDLGA pd = {0};
566  char filename[MAX_PATH];
567  int job_id;
568 
569  if (!GetTempFileNameA(".", "prn", 0, filename))
570  {
571  skip("Failed to create a temporary file name\n");
572  return;
573  }
574 
575  pd.lStructSize = sizeof(pd);
577  pd.nFromPage = 1;
578  pd.nToPage = 1;
579  pd.nCopies = 1;
580 
581  if (!PrintDlgA(&pd))
582  {
583  skip("No default printer available.\n");
584  goto end;
585  }
586  GlobalFree(pd.hDevMode);
587  GlobalFree(pd.hDevNames);
588 
589  ok(pd.hDC != NULL, "PrintDlg didn't return a DC.\n");
590  if (!(print_dc = pd.hDC))
591  goto end;
592 
593  ok(SetAbortProc(print_dc, abort_proc) > 0, "SetAbortProc failed\n");
594  ok(!abort_proc_called, "AbortProc got called unexpectedly by SetAbortProc.\n");
596 
597  doc_info.cbSize = sizeof(doc_info);
598  doc_info.lpszDocName = "Some document";
599  doc_info.lpszOutput = filename;
600 
601  job_id = StartDocA(print_dc, &doc_info);
602 
603  ok(job_id > 0 ||
604  GetLastError() == ERROR_SPL_NO_STARTDOC, /* Vista can fail with this error when using the XPS driver */
605  "StartDocA failed ret %d gle %d\n", job_id, GetLastError());
606 
607  if(job_id <= 0)
608  {
609  skip("StartDoc failed\n");
610  goto end;
611  }
612 
613  /* StartDoc may or may not call abort proc */
614 
616  ok(StartPage(print_dc) > 0, "StartPage failed\n");
617  ok(!abort_proc_called, "AbortProc got called unexpectedly by StartPage.\n");
619 
620  /* following functions sometimes call abort proc too */
621  ok(FillRect(print_dc, &rect, (HBRUSH)(COLOR_BACKGROUND + 1)), "FillRect failed\n");
622  ok(EndPage(print_dc) > 0, "EndPage failed\n");
623  ok(EndDoc(print_dc) > 0, "EndDoc failed\n");
624 
626  ok(DeleteDC(print_dc), "DeleteDC failed\n");
627  ok(!abort_proc_called, "AbortProc got called unexpectedly by DeleteDC.\n");
629 
630 end:
631  SetLastError(0xdeadbeef);
632  if(!DeleteFileA(filename))
633  trace("Failed to delete temporary file (err = %x)\n", GetLastError());
634 }
static HDC
Definition: imagelist.c:92
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
WORD nCopies
Definition: commdlg.h:475
GLuint GLuint end
Definition: gl.h:1545
#define PD_ALLPAGES
Definition: commdlg.h:146
const char * filename
Definition: ioapi.h:135
& rect
Definition: startmenu.cpp:1413
int WINAPI EndPage(_In_ HDC)
int WINAPI StartPage(_In_ HDC)
#define ERROR_SPL_NO_STARTDOC
Definition: winerror.h:1208
WORD nFromPage
Definition: commdlg.h:471
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define PD_RETURNDC
Definition: commdlg.h:155
BOOL WINAPI PrintDlgA(LPPRINTDLGA lppd)
Definition: printdlg.c:2240
LPCSTR lpszOutput
Definition: wingdi.h:1673
#define trace
Definition: atltest.h:70
#define MAX_PATH
Definition: compat.h:26
HGLOBAL hDevMode
Definition: commdlg.h:467
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define SetLastError(x)
Definition: compat.h:409
int cbSize
Definition: wingdi.h:1671
#define PD_PRINTTOFILE
Definition: commdlg.h:152
int WINAPI StartDocA(_In_ HDC, _In_ const DOCINFOA *)
static BOOL abort_proc_called
Definition: printdlg.c:558
#define PD_RETURNDEFAULT
Definition: commdlg.h:157
BOOL WINAPI DeleteDC(_In_ HDC)
LPCSTR lpszDocName
Definition: wingdi.h:1672
HGLOBAL hDevNames
Definition: commdlg.h:468
#define ok(value,...)
Definition: atltest.h:57
DWORD lStructSize
Definition: commdlg.h:465
#define skip(...)
Definition: atltest.h:64
WORD nToPage
Definition: commdlg.h:472
int WINAPI SetAbortProc(_In_ HDC, _In_ ABORTPROC)
DWORD Flags
Definition: commdlg.h:470
static BOOL CALLBACK abort_proc(HDC hdc, int error)
Definition: printdlg.c:559
#define COLOR_BACKGROUND
Definition: hardware.h:164
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HDC hDC
Definition: commdlg.h:469
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
int WINAPI EndDoc(_In_ HDC)

Referenced by START_TEST().

◆ test_PageSetupDlgA()

static void test_PageSetupDlgA ( void  )
static

Definition at line 57 of file printdlg.c.

58 {
59  LPPAGESETUPDLGA pDlg;
60  DWORD res;
61 
62  pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PAGESETUPDLGA)) * 2);
63  if (!pDlg) return;
64 
65  SetLastError(0xdeadbeef);
68  "returned %u with %u and 0x%x (expected '0' and "
69  "CDERR_INITIALIZATION)\n", res, GetLastError(), CommDlgExtendedError());
70 
71  ZeroMemory(pDlg, sizeof(PAGESETUPDLGA));
72  pDlg->lStructSize = sizeof(PAGESETUPDLGA) -1;
73  SetLastError(0xdeadbeef);
74  res = PageSetupDlgA(pDlg);
76  "returned %u with %u and 0x%x (expected '0' and "
77  "CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());
78 
79  ZeroMemory(pDlg, sizeof(PAGESETUPDLGA));
80  pDlg->lStructSize = sizeof(PAGESETUPDLGA) +1;
81  pDlg->Flags = PSD_RETURNDEFAULT;
82  SetLastError(0xdeadbeef);
83  res = PageSetupDlgA(pDlg);
85  "returned %u with %u and 0x%x (expected '0' and CDERR_STRUCTSIZE)\n",
87 
88 
89  ZeroMemory(pDlg, sizeof(PAGESETUPDLGA));
90  pDlg->lStructSize = sizeof(PAGESETUPDLGA);
92  SetLastError(0xdeadbeef);
93  res = PageSetupDlgA(pDlg);
95  "returned %u with %u and 0x%x (expected '!= 0' or '0' and "
96  "PDERR_NODEFAULTPRN)\n", res, GetLastError(), CommDlgExtendedError());
97 
99  skip("No printer configured.\n");
100  HeapFree(GetProcessHeap(), 0, pDlg);
101  return;
102  }
103 
104  ok( pDlg->hDevMode && pDlg->hDevNames,
105  "got %p and %p (expected '!= NULL' for both)\n",
106  pDlg->hDevMode, pDlg->hDevNames);
107 
108  GlobalFree(pDlg->hDevMode);
109  GlobalFree(pDlg->hDevNames);
110 
111  HeapFree(GetProcessHeap(), 0, pDlg);
112 
113 }
HGLOBAL hDevMode
Definition: commdlg.h:435
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg)
Definition: printdlg.c:3911
#define PSD_NOWARNING
Definition: commdlg.h:178
#define CDERR_STRUCTSIZE
Definition: cderr.h:6
#define PDERR_NODEFAULTPRN
Definition: cderr.h:26
smooth NULL
Definition: ftsmooth.c:416
DWORD lStructSize
Definition: commdlg.h:433
DWORD Flags
Definition: commdlg.h:437
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define CDERR_INITIALIZATION
Definition: cderr.h:7
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define SetLastError(x)
Definition: compat.h:409
struct tagPSDA PAGESETUPDLGA
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define PSD_RETURNDEFAULT
Definition: commdlg.h:181
GLuint res
Definition: glext.h:9613
HGLOBAL hDevNames
Definition: commdlg.h:436
DWORD WINAPI CommDlgExtendedError(void)
Definition: cdlg32.c:139
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by START_TEST().

◆ test_PrintDlgA()

static void test_PrintDlgA ( void  )
static

Definition at line 129 of file printdlg.c.

130 {
131  DWORD res, n_copies = 0;
132  LPPRINTDLGA pDlg;
133  DEVNAMES *pDevNames;
134  LPCSTR driver;
135  LPCSTR device;
136  LPCSTR port;
138  LPSTR ptr;
139  DEVMODEA *dm;
140 
141  pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGA)) * 2);
142  if (!pDlg) return;
143 
144 
145  /* will crash with unpatched wine */
146  SetLastError(0xdeadbeef);
147  res = PrintDlgA(NULL);
149  "returned %d with 0x%x and 0x%x (expected '0' and "
150  "CDERR_INITIALIZATION)\n", res, GetLastError(), CommDlgExtendedError());
151 
152  ZeroMemory(pDlg, sizeof(PRINTDLGA));
153  pDlg->lStructSize = sizeof(PRINTDLGA) - 1;
154  SetLastError(0xdeadbeef);
155  res = PrintDlgA(pDlg);
157  "returned %d with 0x%x and 0x%x (expected '0' and "
158  "CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());
159 
160  ZeroMemory(pDlg, sizeof(PRINTDLGA));
161  pDlg->lStructSize = sizeof(PRINTDLGA) + 1;
162  pDlg->Flags = PD_RETURNDEFAULT;
163  SetLastError(0xdeadbeef);
164  res = PrintDlgA(pDlg);
166  "returned %u with %u and 0x%x (expected '0' and "
167  "CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());
168 
169 
170  ZeroMemory(pDlg, sizeof(PRINTDLGA));
171  pDlg->lStructSize = sizeof(PRINTDLGA);
172  pDlg->Flags = PD_RETURNDEFAULT;
173  SetLastError(0xdeadbeef);
174  res = PrintDlgA(pDlg);
176  "returned %d with 0x%x and 0x%x (expected '!= 0' or '0' and "
177  "PDERR_NODEFAULTPRN)\n", res, GetLastError(), CommDlgExtendedError());
178 
180  skip("No printer configured.\n");
181  HeapFree(GetProcessHeap(), 0, pDlg);
182  return;
183  }
184 
185  ok(pDlg->hDevNames != NULL, "(expected '!= NULL')\n");
186  pDevNames = GlobalLock(pDlg->hDevNames);
187  ok(pDevNames != NULL, "(expected '!= NULL')\n");
188 
189  if (pDevNames) {
190  ok(pDevNames->wDriverOffset, "(expected '!= 0' for wDriverOffset)\n");
191  ok(pDevNames->wDeviceOffset, "(expected '!= 0' for wDeviceOffset)\n");
192  ok(pDevNames->wOutputOffset, "(expected '!= 0' for wOutputOffset)\n");
193  ok(pDevNames->wDefault == DN_DEFAULTPRN, "got 0x%x (expected DN_DEFAULTPRN)\n", pDevNames->wDefault);
194 
195  driver = (LPCSTR)pDevNames + pDevNames->wDriverOffset;
196  device = (LPCSTR)pDevNames + pDevNames->wDeviceOffset;
197  port = (LPCSTR)pDevNames + pDevNames->wOutputOffset;
198  trace("driver '%s' device '%s' port '%s'\n", driver, device, port);
199 
200  /* The Driver Entry does not include a Path */
201  ptr = strrchr(driver, '\\');
202  ok( ptr == NULL, "got %p for '%s' (expected NULL for a simple name)\n", ptr, driver);
203 
204  /* The Driver Entry does not have an extension (fixed to ".drv") */
205  ptr = strrchr(driver, '.');
206  todo_wine {
207  ok( ptr == NULL, "got %p for '%s' (expected NULL for no extension)\n", ptr, driver);
208  }
209 
210 
211  buffer[0] = '\0';
212  SetLastError(0xdeadbeef);
214  ptr = strchr(buffer, ',');
215  ok( (res > 1) && (ptr != NULL),
216  "got %u with %u and %p for '%s' (expected '>1' and '!= NULL')\n",
217  res, GetLastError(), ptr, buffer);
218 
219  if (ptr) ptr[0] = '\0';
220  ok( lstrcmpiA(driver, buffer) == 0,
221  "got driver '%s' (expected '%s')\n", driver, buffer);
222 
224  ok(n_copies > 0, "DeviceCapabilities(DC_COPIES) failed\n");
225  }
226 
227  GlobalUnlock(pDlg->hDevNames);
228  GlobalFree(pDlg->hDevMode);
229  GlobalFree(pDlg->hDevNames);
230 
231  /* if device doesn't support printing of multiple copies then
232  * an attempt to set number of copies > 1 in print dialog would
233  * cause the PrintDlg under Windows display the MessageBox and
234  * the test will hang waiting for user response.
235  */
236  if (n_copies > 1)
237  {
238  ZeroMemory(pDlg, sizeof(*pDlg));
239  pDlg->lStructSize = sizeof(*pDlg);
240  pDlg->Flags = PD_ENABLEPRINTHOOK;
242  res = PrintDlgA(pDlg);
243  ok(res, "PrintDlg error %#x\n", CommDlgExtendedError());
244  /* Version of Microsoft XPS Document Writer driver shipped before Win7
245  * reports that it can print multiple copies, but returns 1.
246  */
247  ok(pDlg->nCopies == 123 || broken(pDlg->nCopies == 1), "expected nCopies 123, got %d\n", pDlg->nCopies);
248  ok(pDlg->hDevMode != 0, "hDevMode should not be 0\n");
249  dm = GlobalLock(pDlg->hDevMode);
250  /* some broken drivers use always PD_USEDEVMODECOPIES */
251  ok((S1(U1(*dm)).dmCopies == 1) || broken(S1(U1(*dm)).dmCopies == 123),
252  "expected dm->dmCopies 1, got %d\n", S1(U1(*dm)).dmCopies);
253  GlobalUnlock(pDlg->hDevMode);
254  GlobalFree(pDlg->hDevMode);
255  GlobalFree(pDlg->hDevNames);
256 
257  ZeroMemory(pDlg, sizeof(*pDlg));
258  pDlg->lStructSize = sizeof(*pDlg);
261  res = PrintDlgA(pDlg);
262  ok(res, "PrintDlg error %#x\n", CommDlgExtendedError());
263  ok(pDlg->nCopies == 1, "expected nCopies 1, got %d\n", pDlg->nCopies);
264  ok(pDlg->hDevMode != 0, "hDevMode should not be 0\n");
265  dm = GlobalLock(pDlg->hDevMode);
266  ok(S1(U1(*dm)).dmCopies == 123, "expected dm->dmCopies 123, got %d\n", S1(U1(*dm)).dmCopies);
267  GlobalUnlock(pDlg->hDevMode);
268  GlobalFree(pDlg->hDevMode);
269  GlobalFree(pDlg->hDevNames);
270  }
271 
272  HeapFree(GetProcessHeap(), 0, pDlg);
273 }
static UINT_PTR CALLBACK print_hook_proc(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp)
Definition: printdlg.c:117
#define U1(x)
Definition: test.h:172
int WINAPI lstrcmpiA(LPCSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:42
#define S1(x)
Definition: test.h:191
WORD wDefault
Definition: commdlg.h:300
char CHAR
Definition: xmlstorage.h:175
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
GLuint buffer
Definition: glext.h:5915
WORD nCopies
Definition: commdlg.h:475
static const CHAR emptyA[]
Definition: printdlg.c:52
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
char * LPSTR
Definition: xmlstorage.h:182
#define DN_DEFAULTPRN
Definition: commdlg.h:199
#define CDERR_STRUCTSIZE
Definition: cderr.h:6
#define PDERR_NODEFAULTPRN
Definition: cderr.h:26
Definition: devices.h:37
static PVOID ptr
Definition: dispmode.c:27
WORD wDeviceOffset
Definition: commdlg.h:298
struct @1605::@1606 driver
smooth NULL
Definition: ftsmooth.c:416
WORD wDriverOffset
Definition: commdlg.h:297
BOOL WINAPI PrintDlgA(LPPRINTDLGA lppd)
Definition: printdlg.c:2240
INT WINAPI GetProfileStringA(LPCSTR section, LPCSTR entry, LPCSTR def_val, LPSTR buffer, UINT len)
Definition: profile.c:1252
const char * LPCSTR
Definition: xmlstorage.h:183
LPPRINTHOOKPROC lpfnPrintHook
Definition: commdlg.h:478
#define DC_COPIES
Definition: windef.h:364
#define GetProcessHeap()
Definition: compat.h:395
#define trace
Definition: atltest.h:70
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define CDERR_INITIALIZATION
Definition: cderr.h:7
#define PD_ENABLEPRINTHOOK
Definition: commdlg.h:159
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL hDevMode
Definition: commdlg.h:467
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define SetLastError(x)
Definition: compat.h:409
DWORD WINAPI DeviceCapabilitiesA(_In_ LPCSTR pDevice, _In_opt_ LPCSTR pPort, _In_ WORD fwCapability, _Out_writes_opt_(_Inexpressible_(1)) LPSTR pOutput, _In_opt_ const DEVMODEA *pDevMode)
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define todo_wine
Definition: test.h:154
#define PD_USEDEVMODECOPIES
Definition: commdlg.h:165
#define broken(x)
Definition: _sntprintf.h:21
static const CHAR PrinterPortsA[]
Definition: printdlg.c:53
#define PD_RETURNDEFAULT
Definition: commdlg.h:157
HGLOBAL hDevNames
Definition: commdlg.h:468
#define ok(value,...)
Definition: atltest.h:57
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
char * strchr(const char *String, int ch)
Definition: utclib.c:501
DWORD lStructSize
Definition: commdlg.h:465
#define skip(...)
Definition: atltest.h:64
GLuint res
Definition: glext.h:9613
struct tagPDA PRINTDLGA
DWORD Flags
Definition: commdlg.h:470
WORD wOutputOffset
Definition: commdlg.h:299
DWORD WINAPI CommDlgExtendedError(void)
Definition: cdlg32.c:139
USHORT port
Definition: uri.c:227
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by START_TEST().

◆ test_PrintDlgExW()

static void test_PrintDlgExW ( void  )
static

Definition at line 369 of file printdlg.c.

370 {
371  PRINTPAGERANGE pagerange[2];
372  LPPRINTDLGEXW pDlg;
373  DEVNAMES *dn;
374  HRESULT res;
375 
376  /* PrintDlgEx not present before w2k */
377  if (!pPrintDlgExW) {
378  skip("PrintDlgExW not available\n");
379  return;
380  }
381 
382  if (0) /* Crashes on Win10 */
383  {
384  /* Set CommDlgExtendedError != 0 */
385  PrintDlgA(NULL);
386  SetLastError(0xdeadbeef);
387  res = pPrintDlgExW(NULL);
388  ok( (res == E_INVALIDARG),
389  "got 0x%x with %u and %u (expected 'E_INVALIDARG')\n",
391  }
392 
393  pDlg = HeapAlloc(GetProcessHeap(), 0, (sizeof(PRINTDLGEXW)) + 8);
394  if (!pDlg) return;
395 
396  /* lStructSize must be exact */
397  ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
398  pDlg->lStructSize = sizeof(PRINTDLGEXW) - 1;
399  PrintDlgA(NULL);
400  SetLastError(0xdeadbeef);
401  res = pPrintDlgExW(pDlg);
402  ok( (res == E_INVALIDARG),
403  "got 0x%x with %u and %u (expected 'E_INVALIDARG')\n",
405 
406 
407  ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
408  pDlg->lStructSize = sizeof(PRINTDLGEXW) + 1;
409  PrintDlgA(NULL);
410  SetLastError(0xdeadbeef);
411  res = pPrintDlgExW(pDlg);
412  ok( (res == E_INVALIDARG),
413  "got 0x%x with %u and %u (expected 'E_INVALIDARG')\n",
415 
416 
417  ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
418  pDlg->lStructSize = sizeof(PRINTDLGEXW);
419  SetLastError(0xdeadbeef);
420  res = pPrintDlgExW(pDlg);
421  ok( (res == E_HANDLE),
422  "got 0x%x with %u and %u (expected 'E_HANDLE')\n",
424 
425  /* nStartPage must be START_PAGE_GENERAL for the general page or a valid property sheet index */
426  ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
427  pDlg->lStructSize = sizeof(PRINTDLGEXW);
428  pDlg->hwndOwner = GetDesktopWindow();
429  pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING | PD_NOPAGENUMS;
430  res = pPrintDlgExW(pDlg);
431  ok((res == E_INVALIDARG), "got 0x%x (expected 'E_INVALIDARG')\n", res);
432 
433  /* Use PD_NOPAGENUMS or set nMaxPageRanges and lpPageRanges */
434  ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
435  pDlg->lStructSize = sizeof(PRINTDLGEXW);
436  pDlg->hwndOwner = GetDesktopWindow();
437  pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING;
438  pDlg->nStartPage = START_PAGE_GENERAL;
439  res = pPrintDlgExW(pDlg);
440  ok((res == E_INVALIDARG), "got 0x%x (expected 'E_INVALIDARG')\n", res);
441 
442  /* this is invalid: a valid lpPageRanges with 0 for nMaxPageRanges */
443  ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
444  pDlg->lStructSize = sizeof(PRINTDLGEXW);
445  pDlg->hwndOwner = GetDesktopWindow();
446  pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING;
447  pDlg->lpPageRanges = pagerange;
448  pDlg->nStartPage = START_PAGE_GENERAL;
449  res = pPrintDlgExW(pDlg);
450  ok((res == E_INVALIDARG), "got 0x%x (expected 'E_INVALIDARG')\n", res);
451 
452  /* this is invalid: NULL for lpPageRanges with a valid nMaxPageRanges */
453  ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
454  pDlg->lStructSize = sizeof(PRINTDLGEXW);
455  pDlg->hwndOwner = GetDesktopWindow();
456  pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING;
457  pDlg->nMaxPageRanges = 1;
458  pDlg->nStartPage = START_PAGE_GENERAL;
459  res = pPrintDlgExW(pDlg);
460  ok((res == E_INVALIDARG), "got 0x%x (expected 'E_INVALIDARG')\n", res);
461 
462  /* this works: lpPageRanges with a valid nMaxPageRanges */
463  ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
464  pDlg->lStructSize = sizeof(PRINTDLGEXW);
465  pDlg->hwndOwner = GetDesktopWindow();
466  pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING;
467  pDlg->nMaxPageRanges = 1;
468  pDlg->lpPageRanges = pagerange;
469  pDlg->nStartPage = START_PAGE_GENERAL;
470  res = pPrintDlgExW(pDlg);
471  if (res == E_FAIL)
472  {
473  skip("No printer configured.\n");
474  HeapFree(GetProcessHeap(), 0, pDlg);
475  return;
476  }
477 
478  ok(res == S_OK, "got 0x%x (expected S_OK)\n", res);
479 
480  dn = GlobalLock(pDlg->hDevNames);
481  ok(dn != NULL, "expected '!= NULL' for GlobalLock(%p)\n",pDlg->hDevNames);
482  if (dn)
483  {
484  ok(dn->wDriverOffset, "(expected '!= 0' for wDriverOffset)\n");
485  ok(dn->wDeviceOffset, "(expected '!= 0' for wDeviceOffset)\n");
486  ok(dn->wOutputOffset, "(expected '!= 0' for wOutputOffset)\n");
487  ok(dn->wDefault == DN_DEFAULTPRN, "got 0x%x (expected DN_DEFAULTPRN)\n", dn->wDefault);
488 
489  GlobalUnlock(pDlg->hDevNames);
490  }
491  GlobalFree(pDlg->hDevMode);
492  GlobalFree(pDlg->hDevNames);
493 
494  /* this works also: PD_NOPAGENUMS */
495  ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
496  pDlg->lStructSize = sizeof(PRINTDLGEXW);
497  pDlg->hwndOwner = GetDesktopWindow();
498  pDlg->Flags = PD_RETURNDEFAULT | PD_NOWARNING | PD_NOPAGENUMS;
499  pDlg->nStartPage = START_PAGE_GENERAL;
500  res = pPrintDlgExW(pDlg);
501  ok(res == S_OK, "got 0x%x (expected S_OK)\n", res);
502  GlobalFree(pDlg->hDevMode);
503  GlobalFree(pDlg->hDevNames);
504 
505  /* this works: PD_RETURNDC with PD_RETURNDEFAULT */
506  ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
507  pDlg->lStructSize = sizeof(PRINTDLGEXW);
508  pDlg->hwndOwner = GetDesktopWindow();
510  pDlg->nStartPage = START_PAGE_GENERAL;
511  res = pPrintDlgExW(pDlg);
512  ok(res == S_OK, "got 0x%x (expected S_OK)\n", res);
513  ok(pDlg->hDC != NULL, "HDC missing for PD_RETURNDC\n");
514  GlobalFree(pDlg->hDevMode);
515  GlobalFree(pDlg->hDevNames);
516  DeleteDC(pDlg->hDC);
517 
518  /* this works: PD_RETURNIC with PD_RETURNDEFAULT */
519  ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
520  pDlg->lStructSize = sizeof(PRINTDLGEXW);
521  pDlg->hwndOwner = GetDesktopWindow();
523  pDlg->nStartPage = START_PAGE_GENERAL;
524  res = pPrintDlgExW(pDlg);
525  ok(res == S_OK, "got 0x%x (expected S_OK)\n", res);
526  ok(pDlg->hDC != NULL, "HDC missing for PD_RETURNIC\n");
527  GlobalFree(pDlg->hDevMode);
528  GlobalFree(pDlg->hDevNames);
529  DeleteDC(pDlg->hDC);
530 
531  /* interactive PrintDlgEx tests */
532 
534  {
535  skip("interactive PrintDlgEx tests (set WINETEST_INTERACTIVE=1)\n");
536  HeapFree(GetProcessHeap(), 0, pDlg);
537  return;
538  }
539 
540  ZeroMemory(pDlg, sizeof(PRINTDLGEXW));
541  pDlg->lStructSize = sizeof(PRINTDLGEXW);
542  pDlg->hwndOwner = GetDesktopWindow();
543  pDlg->Flags = PD_NOPAGENUMS | PD_RETURNIC;
544  pDlg->nStartPage = START_PAGE_GENERAL;
545  pDlg->lpCallback = &unknown;
546  pDlg->dwResultAction = S_OK;
547  res = pPrintDlgExW(pDlg);
548  ok(res == S_OK, "got 0x%x (expected S_OK)\n", res);
549  ok(pDlg->dwResultAction == PD_RESULT_PRINT, "expected PD_RESULT_PRINT, got %#x\n", pDlg->dwResultAction);
550  ok(pDlg->hDC != NULL, "HDC missing for PD_RETURNIC\n");
551  GlobalFree(pDlg->hDevMode);
552  GlobalFree(pDlg->hDevNames);
553  DeleteDC(pDlg->hDC);
554 
555  HeapFree(GetProcessHeap(), 0, pDlg);
556 }
#define E_HANDLE
Definition: winerror.h:2850
WORD wDefault
Definition: commdlg.h:300
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
int winetest_interactive
#define PD_NOPAGENUMS
Definition: commdlg.h:150
#define E_FAIL
Definition: ddrawi.h:102
#define DN_DEFAULTPRN
Definition: commdlg.h:199
WORD wDeviceOffset
Definition: commdlg.h:298
#define PD_RETURNIC
Definition: commdlg.h:156
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:652
WORD wDriverOffset
Definition: commdlg.h:297
#define PD_RETURNDC
Definition: commdlg.h:155
BOOL WINAPI PrintDlgA(LPPRINTDLGA lppd)
Definition: printdlg.c:2240
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:77
#define PD_RESULT_PRINT
Definition: commdlg.h:202
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
#define SetLastError(x)
Definition: compat.h:409
#define PD_NOWARNING
Definition: commdlg.h:154
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define START_PAGE_GENERAL
Definition: commdlg.h:205
#define S_OK
Definition: intsafe.h:59
#define PD_RETURNDEFAULT
Definition: commdlg.h:157
BOOL WINAPI DeleteDC(_In_ HDC)
#define ok(value,...)
Definition: atltest.h:57
static IUnknown unknown
Definition: printdlg.c:367
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
#define skip(...)
Definition: atltest.h:64
GLuint res
Definition: glext.h:9613
WORD wOutputOffset
Definition: commdlg.h:299
DWORD WINAPI CommDlgExtendedError(void)
Definition: cdlg32.c:139
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by START_TEST().

◆ unknown_AddRef()

static ULONG WINAPI unknown_AddRef ( IUnknown iface)
static

Definition at line 348 of file printdlg.c.

349 {
350  trace("unknown_AddRef\n");
351  return 2;
352 }
#define trace
Definition: atltest.h:70

◆ unknown_QueryInterface()

static HRESULT WINAPI unknown_QueryInterface ( IUnknown iface,
REFIID  riid,
void **  ppv 
)
static

Definition at line 328 of file printdlg.c.

329 {
330  trace("unknown_QueryInterface %s\n", wine_dbgstr_guid(riid));
331 
332  if (IsEqualGUID(riid, &IID_IPrintDialogCallback))
333  {
334  *ppv = &callback;
335  return S_OK;
336  }
338  {
339  *ppv = NULL;
340  return E_NOINTERFACE;
341  }
342 
343  ok(0, "unexpected IID %s\n", wine_dbgstr_guid(riid));
344  *ppv = NULL;
345  return E_NOINTERFACE;
346 }
#define E_NOINTERFACE
Definition: winerror.h:2364
REFIID riid
Definition: precomp.h:44
REFIID LPVOID * ppv
Definition: atlbase.h:39
const char * wine_dbgstr_guid(const GUID *guid)
smooth NULL
Definition: ftsmooth.c:416
#define trace
Definition: atltest.h:70
const IID IID_IObjectWithSite
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
static IPrintDialogCallback callback
Definition: printdlg.c:326

◆ unknown_Release()

static ULONG WINAPI unknown_Release ( IUnknown iface)
static

Definition at line 354 of file printdlg.c.

355 {
356  trace("unknown_Release\n");
357  return 1;
358 }
#define trace
Definition: atltest.h:70

Variable Documentation

◆ abort_proc_called

BOOL abort_proc_called = FALSE
static

Definition at line 558 of file printdlg.c.

Referenced by abort_proc(), and test_abort_proc().

◆ callback

IPrintDialogCallback callback = { &callback_Vtbl }
static

Definition at line 326 of file printdlg.c.

Referenced by unknown_QueryInterface().

◆ callback_Vtbl

const IPrintDialogCallbackVtbl callback_Vtbl
static
Initial value:
=
{
}
static ULONG WINAPI callback_Release(IPrintDialogCallback *iface)
Definition: printdlg.c:290
static ULONG WINAPI callback_AddRef(IPrintDialogCallback *iface)
Definition: printdlg.c:284
static HRESULT WINAPI callback_QueryInterface(IPrintDialogCallback *iface, REFIID riid, void **ppv)
Definition: printdlg.c:277
static HRESULT WINAPI callback_HandleMessage(IPrintDialogCallback *iface, HWND hdlg, UINT msg, WPARAM wp, LPARAM lp, LRESULT *res)
Definition: printdlg.c:308
static HRESULT WINAPI callback_InitDone(IPrintDialogCallback *iface)
Definition: printdlg.c:296
static HRESULT WINAPI callback_SelectionChange(IPrintDialogCallback *iface)
Definition: printdlg.c:302

Definition at line 316 of file printdlg.c.

◆ emptyA

const CHAR emptyA[] = ""
static

Definition at line 52 of file printdlg.c.

Referenced by test_menu_iteminfo(), test_PrintDlgA(), and test_set_value().

◆ hcomdlg32

HMODULE hcomdlg32
static

Definition at line 47 of file printdlg.c.

Referenced by START_TEST().

◆ IID_IObjectWithSite

◆ PrinterPortsA

const CHAR PrinterPortsA[] = "PrinterPorts"
static

Definition at line 53 of file printdlg.c.

Referenced by test_PrintDlgA().

◆ unknown

IUnknown unknown = { &unknown_Vtbl }
static

Definition at line 367 of file printdlg.c.

Referenced by test_PrintDlgExW().

◆ unknown_Vtbl

const IUnknownVtbl unknown_Vtbl
static
Initial value:
=
{
}
static HRESULT WINAPI unknown_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
Definition: printdlg.c:328
static ULONG WINAPI unknown_Release(IUnknown *iface)
Definition: printdlg.c:354
static ULONG WINAPI unknown_AddRef(IUnknown *iface)
Definition: printdlg.c:348

Definition at line 360 of file printdlg.c.