[FORMATTING]
[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 // Global Variables
11 HANDLE hProcessHeap;
12
13
14 handle_t __RPC_USER
15 WINSPOOL_HANDLE_bind(WINSPOOL_HANDLE wszName)
16 {
17 handle_t hBinding;
18 PWSTR wszStringBinding;
19 RPC_STATUS Status;
20
21 // Get us a string binding handle from the supplied connection information
22 Status = RpcStringBindingComposeW(NULL, L"ncalrpc", wszName, L"spoolss", NULL, &wszStringBinding);
23 if (Status != RPC_S_OK)
24 {
25 ERR("RpcStringBindingComposeW failed with status %ld!\n", Status);
26 return NULL;
27 }
28
29 // Get a handle_t binding handle from the string binding handle
30 Status = RpcBindingFromStringBindingW(wszStringBinding, &hBinding);
31 if (Status != RPC_S_OK)
32 {
33 ERR("RpcBindingFromStringBindingW failed with status %ld!\n", Status);
34 return NULL;
35 }
36
37 // Free the string binding handle
38 Status = RpcStringFreeW(&wszStringBinding);
39 if (Status != RPC_S_OK)
40 {
41 ERR("RpcStringFreeW failed with status %ld!\n", Status);
42 return NULL;
43 }
44
45 return hBinding;
46 }
47
48 void __RPC_USER
49 WINSPOOL_HANDLE_unbind(WINSPOOL_HANDLE wszName, handle_t hBinding)
50 {
51 RPC_STATUS Status;
52
53 Status = RpcBindingFree(&hBinding);
54 if (Status != RPC_S_OK)
55 {
56 ERR("RpcBindingFree failed with status %ld!\n", Status);
57 }
58 }
59
60 void __RPC_FAR* __RPC_USER
61 midl_user_allocate(SIZE_T len)
62 {
63 return HeapAlloc(hProcessHeap, HEAP_ZERO_MEMORY, len);
64 }
65
66 void __RPC_USER
67 midl_user_free(void __RPC_FAR* ptr)
68 {
69 HeapFree(hProcessHeap, 0, ptr);
70 }
71
72 BOOL WINAPI
73 DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
74 {
75 switch (fdwReason)
76 {
77 case DLL_PROCESS_ATTACH:
78 DisableThreadLibraryCalls(hinstDLL);
79 hProcessHeap = GetProcessHeap();
80 break;
81 }
82
83 return TRUE;
84 }
85
86 BOOL WINAPI
87 SpoolerInit()
88 {
89 BOOL bReturnValue = FALSE;
90 DWORD dwErrorCode;
91
92 // Nothing to initialize here yet, but pass this call to the Spool Service as well.
93 RpcTryExcept
94 {
95 dwErrorCode = _RpcSpoolerInit();
96 SetLastError(dwErrorCode);
97 bReturnValue = (dwErrorCode == ERROR_SUCCESS);
98 }
99 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
100 {
101 ERR("_RpcSpoolerInit failed with exception code %lu!\n", RpcExceptionCode());
102 }
103 RpcEndExcept;
104
105 return bReturnValue;
106 }