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
29 #include "ddk/winsplp.h"
30 #include "wine/debug.h"
31 #include "wine/unixlib.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(winspool
);
37 /* ############################### */
39 static CRITICAL_SECTION backend_cs
;
40 static CRITICAL_SECTION_DEBUG backend_cs_debug
=
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")
66 * Failure: FALSE and RPC_S_SERVER_UNAVAILABLE
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
;
79 EnterCriticalSection(&backend_cs
);
80 hlocalspl
= LoadLibraryA("localspl.dll");
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
);
90 LeaveCriticalSection(&backend_cs
);
91 TRACE("backend: %p (%p)\n", backend
, hlocalspl
);
95 FreeLibrary(hlocalspl
);
98 LeaveCriticalSection(&backend_cs
);
100 WARN("failed to load the backend: %lu\n", GetLastError());
101 SetLastError(RPC_S_SERVER_UNAVAILABLE
);
105 /******************************************************************************
108 * Winspool entry point.
111 BOOL WINAPI
DllMain( HINSTANCE instance
, DWORD reason
, void *reserved
)
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();
124 case DLL_PROCESS_DETACH
:
126 DeleteCriticalSection(&backend_cs
);
127 FreeLibrary(hlocalspl
);