[LOCALSPL]
[reactos.git] / reactos / win32ss / printing / base / winspool / monitors.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: Functions related to Print Monitors
5 * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
6 */
7
8 #include "precomp.h"
9
10 static void
11 _MarshallUpMonitorInfo(PBYTE pMonitorInfo, DWORD Level)
12 {
13 PMONITOR_INFO_2W pMonitorInfo2 = (PMONITOR_INFO_2W)pMonitorInfo; // MONITOR_INFO_1W is a subset of MONITOR_INFO_2W
14
15 // Replace relative offset addresses in the output by absolute pointers.
16 pMonitorInfo2->pName = (PWSTR)((ULONG_PTR)pMonitorInfo2->pName + (ULONG_PTR)pMonitorInfo2);
17
18 if (Level == 2)
19 {
20 pMonitorInfo2->pDLLName = (PWSTR)((ULONG_PTR)pMonitorInfo2->pDLLName + (ULONG_PTR)pMonitorInfo2);
21 pMonitorInfo2->pEnvironment = (PWSTR)((ULONG_PTR)pMonitorInfo2->pEnvironment + (ULONG_PTR)pMonitorInfo2);
22 }
23 }
24
25 BOOL WINAPI
26 AddMonitorW(PWSTR pName, DWORD Level, PBYTE pMonitors)
27 {
28 UNIMPLEMENTED;
29 return FALSE;
30 }
31
32 BOOL WINAPI
33 DeleteMonitorW(PWSTR pName, PWSTR pEnvironment, PWSTR pMonitorName)
34 {
35 UNIMPLEMENTED;
36 return FALSE;
37 }
38
39 BOOL WINAPI
40 EnumMonitorsW(PWSTR pName, DWORD Level, PBYTE pMonitors, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
41 {
42 DWORD dwErrorCode;
43 DWORD i;
44 PBYTE p = pMonitors;
45
46 // Do the RPC call
47 RpcTryExcept
48 {
49 dwErrorCode = _RpcEnumMonitors(pName, Level, pMonitors, cbBuf, pcbNeeded, pcReturned);
50 }
51 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
52 {
53 dwErrorCode = RpcExceptionCode();
54 ERR("_RpcEnumPorts failed with exception code %lu!\n", dwErrorCode);
55 }
56 RpcEndExcept;
57
58 if (dwErrorCode == ERROR_SUCCESS)
59 {
60 // Replace relative offset addresses in the output by absolute pointers.
61 for (i = 0; i < *pcReturned; i++)
62 {
63 _MarshallUpMonitorInfo(p, Level);
64
65 if (Level == 1)
66 p += sizeof(MONITOR_INFO_1W);
67 else if (Level == 2)
68 p += sizeof(MONITOR_INFO_2W);
69 }
70 }
71
72 SetLastError(dwErrorCode);
73 return (dwErrorCode == ERROR_SUCCESS);
74 }