ReactOS 0.4.16-dev-334-g4d9f67c
fpSetJob.c File Reference
#include <apitest.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winreg.h>
#include <winspool.h>
#include <winsplp.h>
#include "../localspl_apitest.h"
#include <spoolss.h>
Include dependency graph for fpSetJob.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define MAX_PRINTER_NAME   220
 

Functions

PWSTR GetDefaultPrinterFromRegistry (VOID)
 
BOOL GetLocalsplFuncs (LPPRINTPROVIDOR pp)
 
 START_TEST (fpSetJob)
 

Macro Definition Documentation

◆ MAX_PRINTER_NAME

#define MAX_PRINTER_NAME   220

Definition at line 25 of file fpSetJob.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file fpSetJob.c.

Function Documentation

◆ GetDefaultPrinterFromRegistry()

PWSTR GetDefaultPrinterFromRegistry ( VOID  )

We don't link against winspool, so we don't have GetDefaultPrinterW. We can easily implement a similar function ourselves though.

Definition at line 45 of file main.c.

46{
47 static const WCHAR wszWindowsKey[] = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows";
48 static const WCHAR wszDeviceValue[] = L"Device";
49
50 DWORD cbNeeded;
51 DWORD dwErrorCode;
52 HKEY hWindowsKey = NULL;
53 PWSTR pwszDevice;
54 PWSTR pwszComma;
55 PWSTR pwszReturnValue = NULL;
56
57 // Open the registry key where the default printer for the current user is stored.
58 dwErrorCode = (DWORD)RegOpenKeyExW(HKEY_CURRENT_USER, wszWindowsKey, 0, KEY_READ, &hWindowsKey);
59 if (dwErrorCode != ERROR_SUCCESS)
60 {
61 skip("RegOpenKeyExW failed with status %u!\n", dwErrorCode);
62 goto Cleanup;
63 }
64
65 // Determine the size of the required buffer.
66 dwErrorCode = (DWORD)RegQueryValueExW(hWindowsKey, wszDeviceValue, NULL, NULL, NULL, &cbNeeded);
67 if (dwErrorCode != ERROR_SUCCESS)
68 {
69 skip("RegQueryValueExW failed with status %u!\n", dwErrorCode);
70 goto Cleanup;
71 }
72
73 // Allocate it.
74 pwszDevice = HeapAlloc(GetProcessHeap(), 0, cbNeeded);
75 if (!pwszDevice)
76 {
77 skip("HeapAlloc failed!\n");
78 goto Cleanup;
79 }
80
81 // Now get the actual value.
82 dwErrorCode = RegQueryValueExW(hWindowsKey, wszDeviceValue, NULL, NULL, (PBYTE)pwszDevice, &cbNeeded);
83 if (dwErrorCode != ERROR_SUCCESS)
84 {
85 skip("RegQueryValueExW failed with status %u!\n", dwErrorCode);
86 goto Cleanup;
87 }
88
89 // We get a string "<Printer Name>,winspool,<Port>:".
90 // Extract the printer name from it.
91 pwszComma = wcschr(pwszDevice, L',');
92 if (!pwszComma)
93 {
94 skip("Found no or invalid default printer: %S!\n", pwszDevice);
95 goto Cleanup;
96 }
97
98 // Return the default printer.
99 *pwszComma = 0;
100 pwszReturnValue = pwszDevice;
101
102Cleanup:
103 if (hWindowsKey)
104 RegCloseKey(hWindowsKey);
105
106 return pwszReturnValue;
107}
#define skip(...)
Definition: atltest.h:64
static const WCHAR wszWindowsKey[]
Definition: printers.c:61
static const WCHAR wszDeviceValue[]
Definition: printers.c:62
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
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 GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned long DWORD
Definition: ntddk_ex.h:95
#define KEY_READ
Definition: nt_native.h:1023
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
uint16_t * PWSTR
Definition: typedefs.h:56
#define HKEY_CURRENT_USER
Definition: winreg.h:11
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ GetLocalsplFuncs()

BOOL GetLocalsplFuncs ( LPPRINTPROVIDOR  pp)

Definition at line 110 of file main.c.

111{
112 HMODULE hLocalspl;
113 PInitializePrintProvidor pfnInitializePrintProvidor;
114
115 // Get us a handle to the loaded localspl.dll.
116 hLocalspl = GetModuleHandleW(L"localspl");
117 if (!hLocalspl)
118 {
119 skip("GetModuleHandleW failed with error %u!\n", GetLastError());
120 return FALSE;
121 }
122
123 // Get a pointer to its InitializePrintProvidor function.
124 pfnInitializePrintProvidor = (PInitializePrintProvidor)GetProcAddress(hLocalspl, "InitializePrintProvidor");
125 if (!pfnInitializePrintProvidor)
126 {
127 skip("GetProcAddress failed with error %u!\n", GetLastError());
128 return FALSE;
129 }
130
131 // Get localspl's function pointers.
132 if (!pfnInitializePrintProvidor(pp, sizeof(PRINTPROVIDOR), NULL))
133 {
134 skip("pfnInitializePrintProvidor failed with error %u!\n", GetLastError());
135 return FALSE;
136 }
137
138 return TRUE;
139}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
BOOL(WINAPI * PInitializePrintProvidor)(LPPRINTPROVIDOR, DWORD, LPWSTR)
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( fpSetJob  )

Definition at line 27 of file fpSetJob.c.

28{
29 HANDLE hPrinter = NULL;
31 PWSTR pwszDefaultPrinter = NULL;
32
33 if (!GetLocalsplFuncs(&pp))
34 goto Cleanup;
35
36 // Verify that fpSetJob returns ERROR_INVALID_HANDLE when nothing is provided.
37 ok(!pp.fpSetJob(NULL, 0, 0, NULL, 0), "fpSetJob returns TRUE\n");
38 ok(GetLastError() == ERROR_INVALID_HANDLE, "fpSetJob returns error %lu!\n", GetLastError());
39
40 // Get the default printer.
41 pwszDefaultPrinter = GetDefaultPrinterFromRegistry();
42 if (!pwszDefaultPrinter)
43 {
44 skip("Could not determine the default printer!\n");
45 goto Cleanup;
46 }
47
48 if (!pp.fpOpenPrinter(pwszDefaultPrinter, &hPrinter, NULL))
49 {
50 skip("Could not open a handle to the default printer, last error is %lu!\n", GetLastError());
51 goto Cleanup;
52 }
53
54 // Verify that fpSetJob returns ERROR_INVALID_PARAMETER if only a printer handle is provided.
55 ok(!pp.fpSetJob(hPrinter, 0, 0, NULL, 0), "fpSetJob returns TRUE\n");
56 ok(GetLastError() == ERROR_INVALID_PARAMETER, "fpSetJob returns error %lu!\n", GetLastError());
57
59 if (pwszDefaultPrinter)
60 HeapFree(GetProcessHeap(), 0, pwszDefaultPrinter);
61
62 if (hPrinter)
63 pp.fpClosePrinter(hPrinter);
64}
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define HeapFree(x, y, z)
Definition: compat.h:735
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
PWSTR GetDefaultPrinterFromRegistry(VOID)
Definition: main.c:45
BOOL GetLocalsplFuncs(LPPRINTPROVIDOR pp)
Definition: main.c:110