dmsynth: Correctly handle internal connections with controls.
[wine.git] / dlls / winspool.drv / wspool.c
blob1454cd18e2c9077fda0e550f1f0115abc34f5f18
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;
52 static HMODULE hlocalspl;
53 static BOOL (WINAPI *pInitializePrintProvidor)(LPPRINTPROVIDOR, DWORD, LPWSTR);
54 PRINTPROVIDOR *backend = NULL;
56 /******************************************************************************
57 * load_backend [internal]
59 * load and init our backend (the local printprovider: "localspl.dll")
61 * PARAMS
63 * RETURNS
64 * Success: TRUE
65 * Failure: FALSE and RPC_S_SERVER_UNAVAILABLE
67 * NOTES
68 * In windows, winspool.drv use RPC to interact with the spooler service
69 * (spoolsv.exe with spoolss.dll) and the spooler router (spoolss.dll) interact
70 * with the correct printprovider (localspl.dll for the local system)
73 BOOL load_backend(void)
75 static PRINTPROVIDOR mybackend;
76 DWORD res;
78 EnterCriticalSection(&backend_cs);
79 hlocalspl = LoadLibraryA("localspl.dll");
80 if (hlocalspl) {
81 pInitializePrintProvidor = (void *) GetProcAddress(hlocalspl, "InitializePrintProvidor");
82 if (pInitializePrintProvidor) {
84 /* native localspl does not clear unused entries */
85 memset(&mybackend, 0, sizeof(mybackend));
86 res = pInitializePrintProvidor(&mybackend, sizeof(mybackend), NULL);
87 if (res) {
88 backend = &mybackend;
89 LeaveCriticalSection(&backend_cs);
90 TRACE("backend: %p (%p)\n", backend, hlocalspl);
91 return TRUE;
94 FreeLibrary(hlocalspl);
97 LeaveCriticalSection(&backend_cs);
99 WARN("failed to load the backend: %lu\n", GetLastError());
100 SetLastError(RPC_S_SERVER_UNAVAILABLE);
101 return FALSE;
104 /******************************************************************************
105 * DllMain
107 * Winspool entry point.
110 BOOL WINAPI DllMain( HINSTANCE instance, DWORD reason, void *reserved )
112 switch (reason)
114 case DLL_PROCESS_ATTACH:
115 WINSPOOL_hInstance = instance;
116 DisableThreadLibraryCalls( instance );
117 if (!__wine_init_unix_call())
118 UNIX_CALL( process_attach, NULL );
119 WINSPOOL_LoadSystemPrinters();
120 break;
122 case DLL_PROCESS_DETACH:
123 if (reserved) break;
124 DeleteCriticalSection(&backend_cs);
125 FreeLibrary(hlocalspl);
126 break;
129 return TRUE;