d3dx9: Shader assembler vs_1_0 and vs_1_1 support.
[wine] / dlls / winspool.drv / wspool.c
1 /******************************************************************************
2  * Print Spooler Functions
3  *
4  *
5  * Copyright 1999 Thuy Nguyen
6  *
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.
11  *
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.
16  *
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
20  */
21
22
23 #include "config.h"
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winspool.h"
30
31 #include "winreg.h"
32 #include "ddk/winsplp.h"
33 #include "wine/debug.h"
34
35 #include "wspool.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(winspool);
38
39 /* ############################### */
40
41 static CRITICAL_SECTION backend_cs;
42 static CRITICAL_SECTION_DEBUG backend_cs_debug =
43 {
44     0, 0, &backend_cs,
45     { &backend_cs_debug.ProcessLocksList, &backend_cs_debug.ProcessLocksList },
46       0, 0, { (DWORD_PTR)(__FILE__ ": backend_cs") }
47 };
48 static CRITICAL_SECTION backend_cs = { &backend_cs_debug, -1, 0, 0, 0, 0 };
49
50 /* ############################### */
51
52 HINSTANCE WINSPOOL_hInstance = NULL;
53
54 static HMODULE hlocalspl = NULL;
55 static BOOL (WINAPI *pInitializePrintProvidor)(LPPRINTPROVIDOR, DWORD, LPWSTR);
56
57 PRINTPROVIDOR * backend = NULL;
58
59 /******************************************************************************
60  * load_backend [internal]
61  *
62  * load and init our backend (the local printprovider: "localspl.dll")
63  *
64  * PARAMS
65  *
66  * RETURNS
67  *  Success: TRUE
68  *  Failure: FALSE and RPC_S_SERVER_UNAVAILABLE
69  *
70  * NOTES
71  *  In windows, winspool.drv use RPC to interact with the spooler service
72  *  (spoolsv.exe with spoolss.dll) and the spooler router (spoolss.dll) interact
73  *  with the correct printprovider (localspl.dll for the local system)
74  *
75  */
76 BOOL load_backend(void)
77 {
78     static PRINTPROVIDOR mybackend;
79     DWORD res;
80
81     EnterCriticalSection(&backend_cs);
82     hlocalspl = LoadLibraryA("localspl.dll");
83     if (hlocalspl) {
84         pInitializePrintProvidor = (void *) GetProcAddress(hlocalspl, "InitializePrintProvidor");
85         if (pInitializePrintProvidor) {
86
87             /* native localspl does not clear unused entries */
88             memset(&mybackend, 0, sizeof(mybackend));
89             res = pInitializePrintProvidor(&mybackend, sizeof(mybackend), NULL);
90             if (res) {
91                 backend = &mybackend;
92                 LeaveCriticalSection(&backend_cs);
93                 TRACE("backend: %p (%p)\n", backend, hlocalspl);
94                 return TRUE;
95             }
96         }
97         FreeLibrary(hlocalspl);
98     }
99
100     LeaveCriticalSection(&backend_cs);
101
102     WARN("failed to load the backend: %u\n", GetLastError());
103     SetLastError(RPC_S_SERVER_UNAVAILABLE);
104     return FALSE;
105 }
106
107 /******************************************************************************
108  * unload_backend [internal]
109  *
110  */
111 static void unload_backend(void)
112 {
113     EnterCriticalSection(&backend_cs);
114     backend = NULL;
115     FreeLibrary(hlocalspl);
116     LeaveCriticalSection(&backend_cs);
117 }
118
119
120 /******************************************************************************
121  *  DllMain
122  *
123  * Winspool entry point.
124  *
125  */
126 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD reason, LPVOID lpReserved)
127 {
128   switch (reason)
129   {
130     case DLL_PROCESS_ATTACH: {
131       WINSPOOL_hInstance = hInstance;
132       DisableThreadLibraryCalls(hInstance);
133       WINSPOOL_LoadSystemPrinters();
134       break;
135     }
136     case DLL_PROCESS_DETACH:
137       unload_backend();
138       break;
139   }
140
141   return TRUE;
142 }