[SPOOLSV, WINSPOOL]
[reactos.git] / reactos / win32ss / printing / base / winspool / main.c
1 /*
2 * PROJECT: ReactOS Spooler API
3 * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation
4 * PURPOSE: Main functions
5 * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
6 */
7
8 #include "precomp.h"
9
10 handle_t __RPC_USER
11 WINSPOOL_HANDLE_bind(WINSPOOL_HANDLE wszName)
12 {
13 handle_t hBinding;
14 PWSTR wszStringBinding;
15 RPC_STATUS Status;
16
17 // Get us a string binding handle from the supplied connection information
18 Status = RpcStringBindingComposeW(NULL, L"ncalrpc", wszName, L"spoolss", NULL, &wszStringBinding);
19 if (Status != RPC_S_OK)
20 {
21 ERR("RpcStringBindingComposeW failed with status %ld!\n", Status);
22 return NULL;
23 }
24
25 // Get a handle_t binding handle from the string binding handle
26 Status = RpcBindingFromStringBindingW(wszStringBinding, &hBinding);
27 if (Status != RPC_S_OK)
28 {
29 ERR("RpcBindingFromStringBindingW failed with status %ld!\n", Status);
30 return NULL;
31 }
32
33 // Free the string binding handle
34 Status = RpcStringFreeW(&wszStringBinding);
35 if (Status != RPC_S_OK)
36 {
37 ERR("RpcStringFreeW failed with status %ld!\n", Status);
38 return NULL;
39 }
40
41 return hBinding;
42 }
43
44 void __RPC_USER
45 WINSPOOL_HANDLE_unbind(WINSPOOL_HANDLE wszName, handle_t hBinding)
46 {
47 RPC_STATUS Status;
48
49 Status = RpcBindingFree(&hBinding);
50 if (Status != RPC_S_OK)
51 {
52 ERR("RpcBindingFree failed with status %ld!\n", Status);
53 }
54 }
55
56 void __RPC_FAR* __RPC_USER
57 midl_user_allocate(SIZE_T len)
58 {
59 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
60 }
61
62 void __RPC_USER
63 midl_user_free(void __RPC_FAR* ptr)
64 {
65 HeapFree(GetProcessHeap(), 0, ptr);
66 }
67
68 BOOL WINAPI
69 SpoolerInit()
70 {
71 BOOL bReturnValue = FALSE;
72 DWORD dwErrorCode;
73
74 // Nothing to initialize here yet, but pass this call to the Spool Service as well.
75 RpcTryExcept
76 {
77 dwErrorCode = _RpcSpoolerInit();
78 SetLastError(dwErrorCode);
79 bReturnValue = (dwErrorCode == ERROR_SUCCESS);
80 }
81 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
82 {
83 ERR("_RpcSpoolerInit failed with exception code %lu!\n", RpcExceptionCode());
84 }
85 RpcEndExcept;
86
87 return bReturnValue;
88 }