riched20/tests: Use the available ARRAY_SIZE() macro.
[wine.git] / dlls / spoolss / spoolss_main.c
blob61c565d2faa0c7e5f22dc2f940c7883a05d79abe
1 /*
2 * Implementation of the Spooler-Service helper DLL
4 * Copyright 2006 Detlef Riekenberg
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * 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 "winerror.h"
26 #include "winreg.h"
28 #include "wingdi.h"
29 #include "winspool.h"
30 #include "ddk/winsplp.h"
31 #include "spoolss.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(spoolss);
37 /* ################################ */
39 static HMODULE hwinspool;
41 static const WCHAR winspooldrvW[] = {'w','i','n','s','p','o','o','l','.','d','r','v',0};
43 /******************************************************************************
46 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
48 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
50 switch (fdwReason) {
51 case DLL_WINE_PREATTACH:
52 return FALSE; /* prefer native version */
53 case DLL_PROCESS_ATTACH: {
54 DisableThreadLibraryCalls(hinstDLL);
55 break;
57 case DLL_PROCESS_DETACH:
58 if (lpvReserved) break;
59 backend_unload_all();
60 break;
63 return TRUE;
66 /******************************************************************
67 * AllocSplStr [SPOOLSS.@]
69 * Create a copy from the String on the Spooler-Heap
71 * PARAMS
72 * pwstr [I] PTR to the String to copy
74 * RETURNS
75 * Failure: NULL
76 * Success: PTR to the copied String
79 LPWSTR WINAPI AllocSplStr(LPCWSTR pwstr)
81 LPWSTR res = NULL;
82 DWORD len;
84 TRACE("(%s)\n", debugstr_w(pwstr));
85 if (!pwstr) return NULL;
87 len = (lstrlenW(pwstr) + 1) * sizeof(WCHAR);
88 res = HeapAlloc(GetProcessHeap(), 0, len);
89 if (res) lstrcpyW(res, pwstr);
91 TRACE("returning %p\n", res);
92 return res;
95 /******************************************************************
96 * BuildOtherNamesFromMachineName [SPOOLSS.@]
98 BOOL WINAPI BuildOtherNamesFromMachineName(LPVOID * ptr1, LPVOID * ptr2)
100 FIXME("(%p, %p) stub\n", ptr1, ptr2);
102 *ptr1 = NULL;
103 *ptr2 = NULL;
104 return FALSE;
107 /******************************************************************
108 * DllAllocSplMem [SPOOLSS.@]
110 * Allocate cleared memory from the spooler heap
112 * PARAMS
113 * size [I] Number of bytes to allocate
115 * RETURNS
116 * Failure: NULL
117 * Success: PTR to the allocated memory
119 * NOTES
120 * We use the process heap (Windows use a separate spooler heap)
123 LPVOID WINAPI DllAllocSplMem(DWORD size)
125 LPVOID res;
127 res = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
128 TRACE("(%d) => %p\n", size, res);
129 return res;
132 /******************************************************************
133 * DllFreeSplMem [SPOOLSS.@]
135 * Free the allocated spooler memory
137 * PARAMS
138 * memory [I] PTR to the memory allocated by DllAllocSplMem
140 * RETURNS
141 * Failure: FALSE
142 * Success: TRUE
144 * NOTES
145 * We use the process heap (Windows use a separate spooler heap)
149 BOOL WINAPI DllFreeSplMem(LPBYTE memory)
151 TRACE("(%p)\n", memory);
152 return HeapFree(GetProcessHeap(), 0, memory);
155 /******************************************************************
156 * DllFreeSplStr [SPOOLSS.@]
158 * Free the allocated Spooler-String
160 * PARAMS
161 * pwstr [I] PTR to the WSTR, allocated by AllocSplStr
163 * RETURNS
164 * Failure: FALSE
165 * Success: TRUE
169 BOOL WINAPI DllFreeSplStr(LPWSTR pwstr)
171 TRACE("(%s) PTR: %p\n", debugstr_w(pwstr), pwstr);
172 return HeapFree(GetProcessHeap(), 0, pwstr);
176 /******************************************************************
177 * ImpersonatePrinterClient [SPOOLSS.@]
179 BOOL WINAPI ImpersonatePrinterClient(HANDLE hToken)
181 FIXME("(%p) stub\n", hToken);
182 return TRUE;
185 /******************************************************************
186 * InitializeRouter [SPOOLSS.@]
188 BOOL WINAPI InitializeRouter(void)
190 TRACE("()\n");
191 return backend_load_all();
194 /******************************************************************
195 * IsLocalCall [SPOOLSS.@]
197 BOOL WINAPI IsLocalCall(void)
199 FIXME("() stub\n");
200 return TRUE;
203 /******************************************************************
204 * RevertToPrinterSelf [SPOOLSS.@]
206 HANDLE WINAPI RevertToPrinterSelf(void)
208 FIXME("() stub\n");
209 return (HANDLE) 0xdead0947;
212 /******************************************************************
213 * SplInitializeWinSpoolDrv [SPOOLSS.@]
215 * Dynamic load "winspool.drv" and fill an array with some function-pointer
217 * PARAMS
218 * table [I] array of function-pointer to fill
220 * RETURNS
221 * Success: TRUE
222 * Failure: FALSE
224 * NOTES
225 * Native "spoolss.dll" from w2k fill the table with 11 Function-Pointer.
226 * We implement the XP-Version (The table has only 9 Pointer)
229 BOOL WINAPI SplInitializeWinSpoolDrv(LPVOID * table)
231 DWORD res;
233 TRACE("(%p)\n", table);
235 hwinspool = LoadLibraryW(winspooldrvW);
236 if (!hwinspool) return FALSE;
238 table[0] = (void *) GetProcAddress(hwinspool, "OpenPrinterW");
239 table[1] = (void *) GetProcAddress(hwinspool, "ClosePrinter");
240 table[2] = (void *) GetProcAddress(hwinspool, "SpoolerDevQueryPrintW");
241 table[3] = (void *) GetProcAddress(hwinspool, "SpoolerPrinterEvent");
242 table[4] = (void *) GetProcAddress(hwinspool, "DocumentPropertiesW");
243 table[5] = (void *) GetProcAddress(hwinspool, (LPSTR) 212); /* LoadPrinterDriver */
244 table[6] = (void *) GetProcAddress(hwinspool, (LPSTR) 213); /* RefCntLoadDriver */
245 table[7] = (void *) GetProcAddress(hwinspool, (LPSTR) 214); /* RefCntUnloadDriver */
246 table[8] = (void *) GetProcAddress(hwinspool, (LPSTR) 215); /* ForceUnloadDriver */
248 for (res = 0; res < 9; res++) {
249 if (table[res] == NULL) return FALSE;
252 return TRUE;
256 /******************************************************************
257 * SplIsUpgrade [SPOOLSS.@]
259 BOOL WINAPI SplIsUpgrade(void)
261 FIXME("() stub\n");
262 return FALSE;
265 /******************************************************************
266 * SpoolerHasInitialized [SPOOLSS.@]
268 BOOL WINAPI SpoolerHasInitialized(void)
270 FIXME("() stub\n");
271 return TRUE;
274 /******************************************************************
275 * SpoolerInit [SPOOLSS.@]
277 BOOL WINAPI SpoolerInit(void)
279 FIXME("() stub\n");
280 return TRUE;
283 /******************************************************************
284 * WaitForSpoolerInitialization [SPOOLSS.@]
286 BOOL WINAPI WaitForSpoolerInitialization(void)
288 FIXME("() stub\n");
289 return TRUE;