1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Implementation of the Spooler Setup API (Printing)
*
* Copyright 2007 Detlef Riekenberg
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#define COBJMACROS
#define NONAMELESSUNION
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "wingdi.h"
#include "winnls.h"
#include "winver.h"
#include "winspool.h"
#include "wine/unicode.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(ntprint);
HINSTANCE NTPRINT_hInstance = NULL;
typedef struct {
LPMONITOR_INFO_2W mi2; /* Buffer for installed Monitors */
DWORD installed; /* Number of installed Monitors */
} monitorinfo_t;
/*****************************************************
* DllMain
*/
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
TRACE("(%p, %d, %p)\n",hinstDLL, fdwReason, lpvReserved);
switch(fdwReason)
{
case DLL_WINE_PREATTACH:
return FALSE; /* prefer native version */
case DLL_PROCESS_ATTACH:
NTPRINT_hInstance = hinstDLL;
DisableThreadLibraryCalls( hinstDLL );
break;
}
return TRUE;
}
/*****************************************************
* PSetupCreateMonitorInfo [NTPRINT.@]
*
*
*/
HANDLE WINAPI PSetupCreateMonitorInfo(LPVOID unknown1, LPVOID unknown2,LPVOID unknown3)
{
monitorinfo_t * mi=NULL;
DWORD needed;
DWORD res;
TRACE("(%p, %p, %p)\n", unknown1, unknown2, unknown3);
if ((unknown2 != NULL) || (unknown3 != NULL)) {
FIXME("got unknown parameter: (%p, %p, %p)\n", unknown1, unknown2, unknown3);
return NULL;
}
mi = HeapAlloc(GetProcessHeap(), 0, sizeof(monitorinfo_t));
if (!mi) {
/* FIXME: SetLastError() needed? */
return NULL;
}
/* Get the needed size for all Monitors */
res = EnumMonitorsW(NULL, 2, NULL, 0, &needed, &mi->installed);
if (!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
mi->mi2 = HeapAlloc(GetProcessHeap(), 0, needed);
res = EnumMonitorsW(NULL, 2, (LPBYTE) mi->mi2, needed, &needed, &mi->installed);
}
if (!res) {
HeapFree(GetProcessHeap(), 0, mi);
/* FIXME: SetLastError() needed? */
return NULL;
}
TRACE("=> %p (%u monitors installed)\n", mi, mi->installed);
return mi;
}
/*****************************************************
* PSetupDestroyMonitorInfo [NTPRINT.@]
*
*/
VOID WINAPI PSetupDestroyMonitorInfo(HANDLE monitorinfo)
{
monitorinfo_t * mi = monitorinfo;
TRACE("(%p)\n", mi);
if (mi) {
if (mi->installed) HeapFree(GetProcessHeap(), 0, mi->mi2);
HeapFree(GetProcessHeap(), 0, mi);
}
}
/*****************************************************
* PSetupEnumMonitor [NTPRINT.@]
*
* Copy the selected Monitorname to a buffer
*
* PARAMS
* monitorinfo [I] HANDLE from PSetupCreateMonitorInfo
* index [I] Nr. of the Monitorname to copy
* buffer [I] Target, that receive the Monitorname
* psize [IO] PTR to a DWORD that hold the size of the buffer and receive
* the needed size, when the buffer is too small
*
* RETURNS
* Success: TRUE
* Failure: FALSE
*
* NOTES
* size is in Bytes on w2k and WCHAR on XP
*
*/
BOOL WINAPI PSetupEnumMonitor(HANDLE monitorinfo, DWORD index, LPWSTR buffer, LPDWORD psize)
{
monitorinfo_t * mi = monitorinfo;
LPWSTR nameW;
DWORD len;
TRACE("(%p, %u, %p, %p) => %d\n", mi, index, buffer, psize, psize ? *psize : 0);
if (index < mi->installed) {
nameW = mi->mi2[index].pName;
len = lstrlenW(nameW) + 1;
if (len <= *psize) {
memcpy(buffer, nameW, len * sizeof(WCHAR));
TRACE("#%u: %s\n", index, debugstr_w(buffer));
return TRUE;
}
*psize = len;
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
SetLastError(ERROR_NO_MORE_ITEMS);
return FALSE;
}