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
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(spoolss
);
30 /* ################################ */
32 static HMODULE hwinspool
;
33 static const WCHAR winspooldrvW
[] = {'w','i','n','s','p','o','o','l','.','d','r','v',0};
35 /******************************************************************
38 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
40 TRACE("(%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
43 case DLL_WINE_PREATTACH
:
44 return FALSE
; /* prefer native version */
45 case DLL_PROCESS_ATTACH
: {
46 DisableThreadLibraryCalls(hinstDLL
);
53 /******************************************************************
54 * AllocSplStr [SPOOLSS.@]
56 * Create a copy from the String on the Spooler-Heap
59 * pwstr [I] PTR to the String to copy
63 * Success: PTR to the copied String
66 LPWSTR WINAPI
AllocSplStr(LPCWSTR pwstr
)
71 TRACE("(%s)\n", debugstr_w(pwstr
));
72 if (!pwstr
) return NULL
;
74 len
= (lstrlenW(pwstr
) + 1) * sizeof(WCHAR
);
75 res
= HeapAlloc(GetProcessHeap(), 0, len
);
76 if (res
) lstrcpyW(res
, pwstr
);
78 TRACE("returning %p\n", res
);
82 /******************************************************************
83 * DllAllocSplMem [SPOOLSS.@]
85 * Allocate cleared memory from the spooler heap
88 * size [I] Number of bytes to allocate
92 * Success: PTR to the allocated memory
95 * We use the process heap (Windows use a separate spooler heap)
98 LPVOID WINAPI
DllAllocSplMem(DWORD size
)
102 res
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
103 TRACE("(%d) => %p\n", size
, res
);
107 /******************************************************************
108 * DllFreeSplMem [SPOOLSS.@]
110 * Free the allocated spooler memory
113 * memory [I] PTR to the memory allocated by DllAllocSplMem
120 * We use the process heap (Windows use a separate spooler heap)
124 BOOL WINAPI
DllFreeSplMem(LPBYTE memory
)
126 TRACE("(%p)\n", memory
);
127 return HeapFree(GetProcessHeap(), 0, memory
);
130 /******************************************************************
131 * DllFreeSplStr [SPOOLSS.@]
133 * Free the allocated Spooler-String
136 * pwstr [I] PTR to the WSTR, allocated by AllocSplStr
144 BOOL WINAPI
DllFreeSplStr(LPWSTR pwstr
)
146 TRACE("(%s) PTR: %p\n", debugstr_w(pwstr
), pwstr
);
147 return HeapFree(GetProcessHeap(), 0, pwstr
);
151 /******************************************************************
152 * ImpersonatePrinterClient [SPOOLSS.@]
154 BOOL WINAPI
ImpersonatePrinterClient(HANDLE hToken
)
156 FIXME("(%p) stub\n", hToken
);
160 /******************************************************************
161 * RevertToPrinterSelf [SPOOLSS.@]
163 HANDLE WINAPI
RevertToPrinterSelf(void)
169 /******************************************************************
170 * SplInitializeWinSpoolDrv [SPOOLSS.@]
172 * Dynamic load "winspool.drv" and fill an array with some function-pointer
175 * table [I] array of function-pointer to fill
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)
186 BOOL WINAPI
SplInitializeWinSpoolDrv(LPVOID
* table
)
190 TRACE("(%p)\n", table
);
192 hwinspool
= LoadLibraryW(winspooldrvW
);
193 if (!hwinspool
) return FALSE
;
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 */
205 for (res
= 0; res
< 9; res
++) {
206 if (table
[res
] == NULL
) return FALSE
;