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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright 1998 - 2003 Microsoft Corporation. All Rights Reserved.
//
// FILE: Devmode.cpp
//
// PURPOSE: Implementation of Devmode functions shared with OEM UI and OEM rendering modules.
//
#include "precomp.h"
#include "resource.h"
#include "devmode.h"
#include "debug.h"
// This indicates to Prefast that this is a usermode driver file.
_Analysis_mode_(_Analysis_code_type_user_driver_);
HRESULT hrOEMDevMode(
DWORD dwMode,
POEMDMPARAM pOemDMParam
)
/*++
Routine Description:
Implementation of IPrintOemUni::DevMode.
hrOEMDevMode is called by IPrintOemUni::DevMode
which is defined in intrface.cpp.
The IPrintOemUni::DevMode method, provided by
rendering plug-ins for Unidrv, performs operations
on private DEVMODE members.
Please refer to DDK documentation for more details.
Arguments:
dwMode - caller-supplied constant. Refer to the docs
for more information.
pOemDMParam - pointer to an OEMDMPARAM structure.
Return Value:
S_OK The operation succeeded.
E_FAIL The operation failed.
--*/
{
POEMDEV pOEMDevIn;
POEMDEV pOEMDevOut;
VERBOSE("hrOEMDevMode entry.");
// Verify parameters.
if( (NULL == pOemDMParam)
||
( (OEMDM_SIZE != dwMode)
&&
(OEMDM_DEFAULT != dwMode)
&&
(OEMDM_CONVERT != dwMode)
&&
(OEMDM_MERGE != dwMode)
))
{
ERR("DevMode() ERROR_INVALID_PARAMETER.\r\n");
SetLastError(ERROR_INVALID_PARAMETER);
return E_FAIL;
}
// Cast generic (i.e. PVOID) to OEM private devmode pointer type.
pOEMDevIn = (POEMDEV) pOemDMParam->pOEMDMIn;
pOEMDevOut = (POEMDEV) pOemDMParam->pOEMDMOut;
switch(dwMode)
{
case OEMDM_SIZE:
pOemDMParam->cbBufSize = sizeof(OEMDEV);
break;
case OEMDM_DEFAULT:
pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV);
pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE;
pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION;
pOEMDevOut->dwDriverData = 0;
break;
case OEMDM_CONVERT:
bConvertOEMDevmode(pOEMDevIn, pOEMDevOut);
break;
case OEMDM_MERGE:
bConvertOEMDevmode(pOEMDevIn, pOEMDevOut);
bMakeOEMDevmodeValid(pOEMDevOut);
break;
}
return S_OK;
}
BOOL bConvertOEMDevmode(
PCOEMDEV pOEMDevIn,
POEMDEV pOEMDevOut
)
/*++
Routine Description:
Converts private DEVMODE members to the
current version.
Arguments:
pOEMDevIn - pointer to OEM private devmode
pOEMDevOut - pointer to OEM private devmode
Return Value:
TRUE if successful, FALSE if there is an error
--*/
{
VERBOSE("bConvertOEMDevmode entry.");
if( (NULL == pOEMDevIn)
||
(NULL == pOEMDevOut)
)
{
ERR("ConvertOEMDevmode() invalid parameters.\r\n");
return FALSE;
}
// Check OEM Signature, if it doesn't match ours,
// then just assume DMIn is bad and use defaults.
if(pOEMDevIn->dmOEMExtra.dwSignature == pOEMDevOut->dmOEMExtra.dwSignature)
{
VERBOSE("Converting private OEM Devmode.\r\n");
// Set the devmode defaults so that anything the isn't copied over will
// be set to the default value.
pOEMDevOut->dwDriverData = 0;
// Copy the old structure in to the new using which ever size is the smaller.
// Devmode maybe from newer Devmode (not likely since there is only one), or
// Devmode maybe a newer Devmode, in which case it maybe larger,
// but the first part of the structure should be the same.
// DESIGN ASSUMPTION: the private DEVMODE structure only gets added to;
// the fields that are in the DEVMODE never change only new fields get added to the end.
memcpy(pOEMDevOut, pOEMDevIn, __min(pOEMDevOut->dmOEMExtra.dwSize, pOEMDevIn->dmOEMExtra.dwSize));
// Re-fill in the size and version fields to indicated
// that the DEVMODE is the current private DEVMODE version.
pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV);
pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION;
}
else
{
VERBOSE("Unknown DEVMODE signature, pOEMDMIn ignored.\r\n");
// Don't know what the input DEVMODE is, so just use defaults.
pOEMDevOut->dmOEMExtra.dwSize = sizeof(OEMDEV);
pOEMDevOut->dmOEMExtra.dwSignature = OEM_SIGNATURE;
pOEMDevOut->dmOEMExtra.dwVersion = OEM_VERSION;
pOEMDevOut->dwDriverData = 0;
}
return TRUE;
}
BOOL bMakeOEMDevmodeValid(
POEMDEV pOEMDevmode
)
/*++
Routine Description:
Ensures that private OEM devmode members are valid.
Arguments:
pOEMDevmode - pointer to OEM private devmode
Return Value:
TRUE if successful, FALSE if there is an error
--*/
{
if(NULL == pOEMDevmode)
{
return FALSE;
}
// ASSUMPTION: pOEMDevmode is large enough to contain OEMDEV structure.
// Make sure that dmOEMExtra indicates the current OEMDEV structure.
pOEMDevmode->dmOEMExtra.dwSize = sizeof(OEMDEV);
pOEMDevmode->dmOEMExtra.dwSignature = OEM_SIGNATURE;
pOEMDevmode->dmOEMExtra.dwVersion = OEM_VERSION;
// Set driver data.
pOEMDevmode->dwDriverData = 0;
return TRUE;
}
|