2 * PROJECT: ReactOS Local Spooler API Tests Injected DLL
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Main functions
5 * COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
13 #define WIN32_NO_STATUS
22 #include "../localspl_apitest.h"
28 extern void func_fpEnumPrinters(void);
29 extern void func_fpGetPrintProcessorDirectory(void);
30 extern void func_fpSetJob(void);
32 const struct test winetest_testlist
[] =
34 { "fpEnumPrinters", func_fpEnumPrinters
},
35 { "fpGetPrintProcessorDirectory", func_fpGetPrintProcessorDirectory
},
36 { "fpSetJob", func_fpSetJob
},
41 * We don't link against winspool, so we don't have GetDefaultPrinterW.
42 * We can easily implement a similar function ourselves though.
45 GetDefaultPrinterFromRegistry(VOID
)
47 static const WCHAR wszWindowsKey
[] = L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows";
48 static const WCHAR wszDeviceValue
[] = L
"Device";
52 HKEY hWindowsKey
= NULL
;
55 PWSTR pwszReturnValue
= NULL
;
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
)
61 skip("RegOpenKeyExW failed with status %u!\n", dwErrorCode
);
65 // Determine the size of the required buffer.
66 dwErrorCode
= (DWORD
)RegQueryValueExW(hWindowsKey
, wszDeviceValue
, NULL
, NULL
, NULL
, &cbNeeded
);
67 if (dwErrorCode
!= ERROR_SUCCESS
)
69 skip("RegQueryValueExW failed with status %u!\n", dwErrorCode
);
74 pwszDevice
= HeapAlloc(GetProcessHeap(), 0, cbNeeded
);
77 skip("HeapAlloc failed!\n");
81 // Now get the actual value.
82 dwErrorCode
= RegQueryValueExW(hWindowsKey
, wszDeviceValue
, NULL
, NULL
, (PBYTE
)pwszDevice
, &cbNeeded
);
83 if (dwErrorCode
!= ERROR_SUCCESS
)
85 skip("RegQueryValueExW failed with status %u!\n", dwErrorCode
);
89 // We get a string "<Printer Name>,winspool,<Port>:".
90 // Extract the printer name from it.
91 pwszComma
= wcschr(pwszDevice
, L
',');
94 skip("Found no or invalid default printer: %S!\n", pwszDevice
);
98 // Return the default printer.
100 pwszReturnValue
= pwszDevice
;
104 RegCloseKey(hWindowsKey
);
106 return pwszReturnValue
;
110 GetLocalsplFuncs(LPPRINTPROVIDOR pp
)
113 PInitializePrintProvidor pfnInitializePrintProvidor
;
115 // Get us a handle to the loaded localspl.dll.
116 hLocalspl
= GetModuleHandleW(L
"localspl");
119 skip("GetModuleHandleW failed with error %u!\n", GetLastError());
123 // Get a pointer to its InitializePrintProvidor function.
124 pfnInitializePrintProvidor
= (PInitializePrintProvidor
)GetProcAddress(hLocalspl
, "InitializePrintProvidor");
125 if (!pfnInitializePrintProvidor
)
127 skip("GetProcAddress failed with error %u!\n", GetLastError());
131 // Get localspl's function pointers.
132 if (!pfnInitializePrintProvidor(pp
, sizeof(PRINTPROVIDOR
), NULL
))
134 skip("pfnInitializePrintProvidor failed with error %u!\n", GetLastError());
142 GetSpoolssFunc(const char* FunctionName
)
146 // Get us a handle to the loaded spoolss.dll.
147 hSpoolss
= GetModuleHandleW(L
"spoolss");
150 skip("GetModuleHandleW failed with error %u!\n", GetLastError());
154 return GetProcAddress(hSpoolss
, FunctionName
);
157 // Running the tests from the injected DLL and redirecting their output to the pipe.
159 DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
161 char szTestName
[150];
167 // We only want to run our test once when the DLL is injected to the process.
168 if (fdwReason
!= DLL_PROCESS_ATTACH
)
171 // Read the test to run from the command pipe.
172 hCommandPipe
= CreateFileW(COMMAND_PIPE_NAME
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
173 if (hCommandPipe
== INVALID_HANDLE_VALUE
)
175 DPRINT("DLL: CreateFileW failed for the command pipe with error %lu!\n", GetLastError());
179 if (!ReadFile(hCommandPipe
, szTestName
, sizeof(szTestName
), &cbRead
, NULL
))
181 DPRINT("DLL: ReadFile failed for the command pipe with error %lu!\n", GetLastError());
185 CloseHandle(hCommandPipe
);
187 // Check if the test name is valid.
188 if (!find_test(szTestName
))
190 DPRINT("DLL: Got invalid test name \"%s\"!\n", szTestName
);
194 // Backup our current stdout and set it to the output pipe.
195 iOldStdout
= _dup(_fileno(stdout
));
196 fpStdout
= _wfreopen(OUTPUT_PIPE_NAME
, L
"w", stdout
);
197 setbuf(stdout
, NULL
);
200 run_test(szTestName
);
202 // Restore stdout to the previous value.
204 _dup2(iOldStdout
, _fileno(stdout
));
206 // Return FALSE so that our DLL is immediately unloaded.