gdi32/tests: Mark tests failing randomly on Windows as flaky.
[wine.git] / dlls / winspool.drv / wspool.c
blobff0e4418719908e43ea286c000a2ff5c2e604af9
1 /******************************************************************************
2 * Print Spooler Functions
5 * Copyright 1999 Thuy Nguyen
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winspool.h"
27 #include "winreg.h"
28 #include "winternl.h"
29 #include "ddk/winsplp.h"
30 #include "wine/debug.h"
31 #include "wine/unixlib.h"
33 #include "wspool.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(winspool);
37 /* ############################### */
39 static CRITICAL_SECTION backend_cs;
40 static CRITICAL_SECTION_DEBUG backend_cs_debug =
42 0, 0, &backend_cs,
43 { &backend_cs_debug.ProcessLocksList, &backend_cs_debug.ProcessLocksList },
44 0, 0, { (DWORD_PTR)(__FILE__ ": backend_cs") }
46 static CRITICAL_SECTION backend_cs = { &backend_cs_debug, -1, 0, 0, 0, 0 };
48 /* ############################### */
50 HINSTANCE WINSPOOL_hInstance = NULL;
51 unixlib_handle_t winspool_handle = 0;
53 static HMODULE hlocalspl;
54 static BOOL (WINAPI *pInitializePrintProvidor)(LPPRINTPROVIDOR, DWORD, LPWSTR);
55 PRINTPROVIDOR *backend = NULL;
57 /******************************************************************************
58 * load_backend [internal]
60 * load and init our backend (the local printprovider: "localspl.dll")
62 * PARAMS
64 * RETURNS
65 * Success: TRUE
66 * Failure: FALSE and RPC_S_SERVER_UNAVAILABLE
68 * NOTES
69 * In windows, winspool.drv use RPC to interact with the spooler service
70 * (spoolsv.exe with spoolss.dll) and the spooler router (spoolss.dll) interact
71 * with the correct printprovider (localspl.dll for the local system)
74 BOOL load_backend(void)
76 static PRINTPROVIDOR mybackend;
77 DWORD res;
79 EnterCriticalSection(&backend_cs);
80 hlocalspl = LoadLibraryA("localspl.dll");
81 if (hlocalspl) {
82 pInitializePrintProvidor = (void *) GetProcAddress(hlocalspl, "InitializePrintProvidor");
83 if (pInitializePrintProvidor) {
85 /* native localspl does not clear unused entries */
86 memset(&mybackend, 0, sizeof(mybackend));
87 res = pInitializePrintProvidor(&mybackend, sizeof(mybackend), NULL);
88 if (res) {
89 backend = &mybackend;
90 LeaveCriticalSection(&backend_cs);
91 TRACE("backend: %p (%p)\n", backend, hlocalspl);
92 return TRUE;
95 FreeLibrary(hlocalspl);
98 LeaveCriticalSection(&backend_cs);
100 WARN("failed to load the backend: %lu\n", GetLastError());
101 SetLastError(RPC_S_SERVER_UNAVAILABLE);
102 return FALSE;
105 /******************************************************************************
106 * DllMain
108 * Winspool entry point.
111 BOOL WINAPI DllMain( HINSTANCE instance, DWORD reason, void *reserved )
113 switch (reason)
115 case DLL_PROCESS_ATTACH:
116 WINSPOOL_hInstance = instance;
117 DisableThreadLibraryCalls( instance );
118 if (!NtQueryVirtualMemory( GetCurrentProcess(), instance, MemoryWineUnixFuncs,
119 &winspool_handle, sizeof(winspool_handle), NULL ))
120 UNIX_CALL( process_attach, NULL );
121 WINSPOOL_LoadSystemPrinters();
122 break;
124 case DLL_PROCESS_DETACH:
125 if (reserved) break;
126 DeleteCriticalSection(&backend_cs);
127 FreeLibrary(hlocalspl);
128 break;
131 return TRUE;