1 /* 2 * PROJECT: ReactOS Spooler API 3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) 4 * PURPOSE: Main functions 5 * COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org) 6 */ 7 8 #include "precomp.h" 9 10 // Global Variables 11 HANDLE hProcessHeap; 12 HINSTANCE hinstWinSpool = NULL; 13 CRITICAL_SECTION rtlCritSec; 14 15 handle_t __RPC_USER 16 WINSPOOL_HANDLE_bind(WINSPOOL_HANDLE wszName) 17 { 18 handle_t hBinding; 19 PWSTR wszStringBinding; 20 RPC_STATUS Status; 21 22 // Get us a string binding handle from the supplied connection information 23 Status = RpcStringBindingComposeW(NULL, L"ncalrpc", NULL, L"spoolss", NULL, &wszStringBinding); 24 if (Status != RPC_S_OK) 25 { 26 ERR("RpcStringBindingComposeW failed with status %ld!\n", Status); 27 return NULL; 28 } 29 30 // Get a handle_t binding handle from the string binding handle 31 Status = RpcBindingFromStringBindingW(wszStringBinding, &hBinding); 32 if (Status != RPC_S_OK) 33 { 34 ERR("RpcBindingFromStringBindingW failed with status %ld!\n", Status); 35 return NULL; 36 } 37 38 // Free the string binding handle 39 Status = RpcStringFreeW(&wszStringBinding); 40 if (Status != RPC_S_OK) 41 { 42 ERR("RpcStringFreeW failed with status %ld!\n", Status); 43 return NULL; 44 } 45 46 return hBinding; 47 } 48 49 void __RPC_USER 50 WINSPOOL_HANDLE_unbind(WINSPOOL_HANDLE wszName, handle_t hBinding) 51 { 52 RPC_STATUS Status; 53 54 Status = RpcBindingFree(&hBinding); 55 if (Status != RPC_S_OK) 56 { 57 ERR("RpcBindingFree failed with status %ld!\n", Status); 58 } 59 } 60 61 void __RPC_FAR* __RPC_USER 62 midl_user_allocate(SIZE_T len) 63 { 64 return HeapAlloc(hProcessHeap, HEAP_ZERO_MEMORY, len); 65 } 66 67 void __RPC_USER 68 midl_user_free(void __RPC_FAR* ptr) 69 { 70 HeapFree(hProcessHeap, 0, ptr); 71 } 72 73 BOOL WINAPI 74 DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 75 { 76 TRACE("DllMain(%p, %lu, %p)\n", hinstDLL, fdwReason, lpvReserved); 77 78 switch (fdwReason) 79 { 80 case DLL_PROCESS_ATTACH: 81 DisableThreadLibraryCalls(hinstDLL); 82 hProcessHeap = GetProcessHeap(); 83 hinstWinSpool = hinstDLL; 84 InitializeCriticalSection(&rtlCritSec); 85 break; 86 87 case DLL_PROCESS_DETACH: 88 DeleteCriticalSection(&rtlCritSec); 89 break; 90 } 91 92 return TRUE; 93 } 94 95 BOOL WINAPI 96 SpoolerInit(VOID) 97 { 98 BOOL bReturnValue = FALSE; 99 DWORD dwErrorCode; 100 101 TRACE("SpoolerInit()\n"); 102 103 // Nothing to initialize here yet, but pass this call to the Spool Service as well. 104 RpcTryExcept 105 { 106 dwErrorCode = _RpcSpoolerInit(); 107 SetLastError(dwErrorCode); 108 bReturnValue = (dwErrorCode == ERROR_SUCCESS); 109 } 110 RpcExcept(EXCEPTION_EXECUTE_HANDLER) 111 { 112 ERR("_RpcSpoolerInit failed with exception code %lu!\n", RpcExceptionCode()); 113 } 114 RpcEndExcept; 115 116 return bReturnValue; 117 } 118