wintrust: Add a helper function to initialize chain creation parameters.
[wine] / dlls / spoolss / spoolss_main.c
1 /*
2  * Implementation of the Spooler-Service helper DLL
3  *
4  * Copyright 2006 Detlef Riekenberg
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(spoolss);
29
30 /* ################################ */
31
32 static HMODULE hwinspool;
33 static const WCHAR winspooldrvW[] = {'w','i','n','s','p','o','o','l','.','d','r','v',0};
34
35 /******************************************************************
36  *
37  */
38 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
39 {
40     TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
41
42     switch (fdwReason) {
43         case DLL_WINE_PREATTACH:
44             return FALSE;  /* prefer native version */
45         case DLL_PROCESS_ATTACH: {
46             DisableThreadLibraryCalls(hinstDLL);
47             break;
48         }
49     }
50     return TRUE;
51 }
52
53 /******************************************************************
54  *   AllocSplStr   [SPOOLSS.@]
55  *
56  * Create a copy from the String on the Spooler-Heap
57  *
58  * PARAMS
59  *  pwstr [I] PTR to the String to copy
60  *
61  * RETURNS
62  *  Failure: NULL
63  *  Success: PTR to the copied String
64  *
65  */
66 LPWSTR WINAPI AllocSplStr(LPCWSTR pwstr)
67 {
68     LPWSTR  res = NULL;
69     DWORD   len;
70
71     TRACE("(%s)\n", debugstr_w(pwstr));
72     if (!pwstr) return NULL;
73
74     len = (lstrlenW(pwstr) + 1) * sizeof(WCHAR);
75     res = HeapAlloc(GetProcessHeap(), 0, len);
76     if (res) lstrcpyW(res, pwstr);
77         
78     TRACE("returning %p\n", res);
79     return res;
80 }
81
82 /******************************************************************
83  *   DllAllocSplMem   [SPOOLSS.@]
84  *
85  * Allocate cleared memory from the spooler heap
86  *
87  * PARAMS
88  *  size [I] Number of bytes to allocate
89  *
90  * RETURNS
91  *  Failure: NULL
92  *  Success: PTR to the allocated memory
93  *
94  * NOTES
95  *  We use the process heap (Windows use a separate spooler heap)
96  *
97  */
98 LPVOID WINAPI DllAllocSplMem(DWORD size)
99 {
100     LPVOID  res;
101
102     res = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
103     TRACE("(%d) => %p\n", size, res);
104     return res;
105 }
106
107 /******************************************************************
108  *   DllFreeSplMem   [SPOOLSS.@]
109  *
110  * Free the allocated spooler memory
111  *
112  * PARAMS
113  *  memory [I] PTR to the memory allocated by DllAllocSplMem
114  *
115  * RETURNS
116  *  Failure: FALSE
117  *  Success: TRUE
118  *
119  * NOTES
120  *  We use the process heap (Windows use a separate spooler heap)
121  *
122  */
123
124 BOOL WINAPI DllFreeSplMem(LPBYTE memory)
125 {
126     TRACE("(%p)\n", memory);
127     return HeapFree(GetProcessHeap(), 0, memory);
128 }
129
130 /******************************************************************
131  *   DllFreeSplStr   [SPOOLSS.@]
132  *
133  * Free the allocated Spooler-String
134  *
135  * PARAMS
136  *  pwstr [I] PTR to the WSTR, allocated by AllocSplStr
137  *
138  * RETURNS
139  *  Failure: FALSE
140  *  Success: TRUE
141  *
142  */
143
144 BOOL WINAPI DllFreeSplStr(LPWSTR pwstr)
145 {
146     TRACE("(%s) PTR: %p\n", debugstr_w(pwstr), pwstr);
147     return HeapFree(GetProcessHeap(), 0, pwstr);
148 }
149
150
151 /******************************************************************
152  *   ImpersonatePrinterClient   [SPOOLSS.@]
153  */
154 BOOL WINAPI ImpersonatePrinterClient(HANDLE hToken)
155 {
156     FIXME("(%p) stub\n", hToken);
157     return TRUE;
158 }
159
160 /******************************************************************
161  *   RevertToPrinterSelf   [SPOOLSS.@]
162  */
163 HANDLE WINAPI RevertToPrinterSelf(void)
164 {
165     FIXME("() stub\n");
166     return NULL;
167 }
168
169 /******************************************************************
170  *   SplInitializeWinSpoolDrv   [SPOOLSS.@]
171  *
172  * Dynamic load "winspool.drv" and fill an array with some function-pointer
173  *
174  * PARAMS
175  *  table  [I] array of function-pointer to fill
176  *
177  * RETURNS
178  *  Success: TRUE
179  *  Failure: FALSE
180  *
181  * NOTES
182  *  Native "spoolss.dll" from w2k fill the table with 11 Function-Pointer.
183  *  We implement the XP-Version (The table has only 9 Pointer)
184  *
185  */
186 BOOL WINAPI SplInitializeWinSpoolDrv(LPVOID * table)
187 {
188     DWORD res;
189
190     TRACE("(%p)\n", table);
191
192     hwinspool = LoadLibraryW(winspooldrvW);
193     if (!hwinspool) return FALSE;
194
195     table[0] = (void *) GetProcAddress(hwinspool, "OpenPrinterW");
196     table[1] = (void *) GetProcAddress(hwinspool, "ClosePrinter");
197     table[2] = (void *) GetProcAddress(hwinspool, "SpoolerDevQueryPrintW");
198     table[3] = (void *) GetProcAddress(hwinspool, "SpoolerPrinterEvent");
199     table[4] = (void *) GetProcAddress(hwinspool, "DocumentPropertiesW");
200     table[5] = (void *) GetProcAddress(hwinspool, (LPSTR) 212);  /* LoadPrinterDriver */
201     table[6] = (void *) GetProcAddress(hwinspool, (LPSTR) 213);  /* RefCntLoadDriver */
202     table[7] = (void *) GetProcAddress(hwinspool, (LPSTR) 214);  /* RefCntUnloadDriver */
203     table[8] = (void *) GetProcAddress(hwinspool, (LPSTR) 215);  /* ForceUnloadDriver */
204
205     for (res = 0; res < 9; res++) {
206         if (table[res] == NULL) return FALSE;
207     }
208
209     return TRUE;
210
211 }