4a3689512651ce5f63ef9765403ba7d48c5c5452
[reactos.git] / win32ss / printing / base / winspool / monitors.c
1 /*
2 * PROJECT: ReactOS Spooler API
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Functions related to Print Monitors
5 * COPYRIGHT: Copyright 2015-2017 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 AddMonitorA(PSTR pName, DWORD Level, PBYTE pMonitors)
27 {
28 TRACE("AddMonitorA(%s, %lu, %p)\n", pName, Level, pMonitors);
29 UNIMPLEMENTED;
30 return FALSE;
31 }
32
33 BOOL WINAPI
34 AddMonitorW(PWSTR pName, DWORD Level, PBYTE pMonitors)
35 {
36 TRACE("AddMonitorW(%S, %lu, %p)\n", pName, Level, pMonitors);
37 UNIMPLEMENTED;
38 return FALSE;
39 }
40
41 BOOL WINAPI
42 DeleteMonitorA(PSTR pName, PSTR pEnvironment, PSTR pMonitorName)
43 {
44 TRACE("DeleteMonitorA(%s, %s, %s)\n", pName, pEnvironment, pMonitorName);
45 UNIMPLEMENTED;
46 return FALSE;
47 }
48
49 BOOL WINAPI
50 DeleteMonitorW(PWSTR pName, PWSTR pEnvironment, PWSTR pMonitorName)
51 {
52 TRACE("DeleteMonitorW(%S, %S, %S)\n", pName, pEnvironment, pMonitorName);
53 UNIMPLEMENTED;
54 return FALSE;
55 }
56
57 BOOL WINAPI
58 EnumMonitorsA(PSTR pName, DWORD Level, PBYTE pMonitors, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
59 {
60 TRACE("EnumMonitorsA(%s, %lu, %p, %lu, %p, %p)\n", pName, Level, pMonitors, cbBuf, pcbNeeded, pcReturned);
61 UNIMPLEMENTED;
62 return FALSE;
63 }
64
65 BOOL WINAPI
66 EnumMonitorsW(PWSTR pName, DWORD Level, PBYTE pMonitors, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
67 {
68 DWORD dwErrorCode;
69 DWORD i;
70 PBYTE p = pMonitors;
71
72 TRACE("EnumMonitorsW(%S, %lu, %p, %lu, %p, %p)\n", pName, Level, pMonitors, cbBuf, pcbNeeded, pcReturned);
73
74 // Do the RPC call
75 RpcTryExcept
76 {
77 dwErrorCode = _RpcEnumMonitors(pName, Level, pMonitors, cbBuf, pcbNeeded, pcReturned);
78 }
79 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
80 {
81 dwErrorCode = RpcExceptionCode();
82 ERR("_RpcEnumPorts failed with exception code %lu!\n", dwErrorCode);
83 }
84 RpcEndExcept;
85
86 if (dwErrorCode == ERROR_SUCCESS)
87 {
88 // Replace relative offset addresses in the output by absolute pointers.
89 for (i = 0; i < *pcReturned; i++)
90 {
91 _MarshallUpMonitorInfo(p, Level);
92
93 if (Level == 1)
94 p += sizeof(MONITOR_INFO_1W);
95 else if (Level == 2)
96 p += sizeof(MONITOR_INFO_2W);
97 }
98 }
99
100 SetLastError(dwErrorCode);
101 return (dwErrorCode == ERROR_SUCCESS);
102 }