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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
|
/*++
Copyright (c) 2005 Microsoft Corporation
All rights reserved.
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.
File Name:
ftrdmptcnv.h
Abstract:
Defines the interface for a DevMode <-> PrintTicket feature conversion class
and an abstract class that handles the print core helper interface pointer.
--*/
#pragma once
template <typename _T = INT>
struct GPDStringToOption
{
PCSTR pszOption;
_T option;
};
class IFeatureDMPTConvert
{
public:
IFeatureDMPTConvert(){}
virtual ~IFeatureDMPTConvert(){}
virtual HRESULT STDMETHODCALLTYPE
ConvertPrintTicketToDevMode(
_In_ IXMLDOMDocument2* pPrintTicket,
_In_ ULONG cbDevmode,
_Inout_ PDEVMODE pDevmode,
_In_ ULONG cbDrvPrivateSize,
_In_ PVOID pPrivateDevmode
) = 0;
virtual HRESULT STDMETHODCALLTYPE
ConvertDevModeToPrintTicket(
_In_ ULONG cbDevmode,
_In_ PDEVMODE pDevmode,
_In_ ULONG cbDrvPrivateSize,
_In_ PVOID pPrivateDevmode,
_Inout_ IXMLDOMDocument2* pPrintTicket
) = 0;
virtual HRESULT STDMETHODCALLTYPE
CompletePrintCapabilities(
_In_opt_ IXMLDOMDocument2* pPrintTicket,
_Inout_ IXMLDOMDocument2* pPrintCapabilities
) = 0;
virtual HRESULT STDMETHODCALLTYPE
PublishPrintTicketHelperInterface(
_In_ IPrintCoreHelperUni* pHelper
) = 0;
virtual HRESULT STDMETHODCALLTYPE
ValidatePrintTicket(
_Inout_ IXMLDOMDocument2* pPrintTicket
) = 0;
};
template <typename _T>
class CFeatureDMPTConvert : public IFeatureDMPTConvert
{
public:
CFeatureDMPTConvert(){}
virtual ~CFeatureDMPTConvert(){}
/*++
Routine Name:
ConvertPrintTicketToDevMode
Routine Description:
The plug-in is passed an input Print Ticket that is fully populated,
and a devmode. This method controls the calls to update the DevMode
to reflect the settings defined in the PrintTicket.
The template this class is instantiated using defines the data
type passed between routines. Derived classes define this data
and then act on it as appropriate to the feature.
Arguments:
pPrintTicket - pointer to input Print Ticket
cbDevmode - size in bytes of input full devmode
pDevmode - pointer to input full devmode buffer
cbDrvPrivateSize - buffer size in bytes of plug-in private devmode
pPrivateDevmode - pointer to plug-in private devmode buffer
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT STDMETHODCALLTYPE
ConvertPrintTicketToDevMode(
_In_ IXMLDOMDocument2* pPrintTicket,
_In_ ULONG cbDevmode,
_Inout_ PDEVMODE pDevmode,
_In_ ULONG cbDrvPrivateSize,
_In_ PVOID pPrivateDevmode
)
{
HRESULT hr = S_OK;
//
// Validate parameters
//
if (SUCCEEDED(hr = CHECK_POINTER(pDevmode, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pPrivateDevmode, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pPrintTicket, E_POINTER)))
{
if (cbDevmode < sizeof(DEVMODE) ||
cbDrvPrivateSize == 0)
{
hr = E_INVALIDARG;
}
}
if (SUCCEEDED(hr))
{
//
// Initialise the GPD settings from the devmode and merge with
// the PrintTicket settings
//
_T ptData;
if (SUCCEEDED(hr = GetPTDataSettingsFromDM(pDevmode, cbDevmode, pPrivateDevmode, cbDrvPrivateSize, &ptData)) &&
SUCCEEDED(hr = MergePTDataSettingsWithPT(pPrintTicket, &ptData)))
{
//
// Set the combined options in the devmode
//
hr = SetPTDataInDM(ptData, pDevmode, cbDevmode, pPrivateDevmode, cbDrvPrivateSize);
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
ConvertDevModeToPrintTicket
Routine Description:
Unidrv will call the routine with an Input PrintTicket that is
populated with public and Unidrv private features. This method
controls the calls to update the PrintTicket to reflect the
settings defined in the devmode.
The template this class is instantiated using defines the data
type passed between routines. Derived classes define this data
and then act on it as appropriate to the feature.
Arguments:
cbDevmode - size in bytes of input full devmode
pDevmode - pointer to input full devmode buffer
cbDrvPrivateSize - buffer size in bytes of plug-in private devmode
pPrivateDevmode - pointer to plug-in private devmode buffer
pPrintTicket - pointer to input Print Ticket
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT STDMETHODCALLTYPE
ConvertDevModeToPrintTicket(
_In_ ULONG cbDevmode,
_In_ PDEVMODE pDevmode,
_In_ ULONG cbDrvPrivateSize,
_In_ PVOID pPrivateDevmode,
_Inout_ IXMLDOMDocument2* pPrintTicket
)
{
HRESULT hr = S_OK;
//
// Validate parameters
//
if (SUCCEEDED(hr = CHECK_POINTER(pDevmode, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pPrivateDevmode, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pPrintTicket, E_POINTER)))
{
if (cbDevmode < sizeof(DEVMODE) ||
cbDrvPrivateSize == 0)
{
hr = E_INVALIDARG;
}
}
if (SUCCEEDED(hr))
{
//
// Initialise the GPD settings from the devmode
//
_T ptData;
if (SUCCEEDED(hr = GetPTDataSettingsFromDM(pDevmode, cbDevmode, pPrivateDevmode, cbDrvPrivateSize, &ptData)))
{
//
// Set the options in the PrintTicket
//
hr = SetPTDataInPT(ptData, pPrintTicket);
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
PublishPrintTicketHelperInterface
Routine Description:
This routine is stores the print core helper interface for use by
derived feature specific DM<->PT conversion classes.
Arguments:
pHelper - Pointer to core helper interface
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT STDMETHODCALLTYPE
PublishPrintTicketHelperInterface(
_In_ IPrintCoreHelperUni* pHelper
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pHelper, E_POINTER)) &&
m_pCoreHelper == NULL)
{
m_pCoreHelper = pHelper;
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
ValidatePrintTicket
Routine Description:
Default validate implementation - just returns S_NO_CONFLICT. If the
derived feature specific class needs to validate the PrintTicket it
should provide its own implementation and handle the PrintTicket
appropriately.
Arguments:
pPrintTicket - Pointer to input Print Ticket.
Return Value:
HRESULT
S_NO_CONFLICT - On success
E_* - On error
--*/
virtual HRESULT STDMETHODCALLTYPE
ValidatePrintTicket(
_Inout_ IXMLDOMDocument2* pPrintTicket
)
{
HRESULT hr = S_NO_CONFLICT;
if (SUCCEEDED(hr = CHECK_POINTER(pPrintTicket, E_POINTER)))
{
hr = S_NO_CONFLICT;
}
ERR_ON_HR(hr);
return hr;
}
protected:
/*++
Routine Name:
GetPTDataSettingsFromDM
Routine Description:
This pure virtual function ensures the concrete feature converter class
implements a means of retrieving the data type defined by that class from
the DevMode.
Arguments:
pDevmode - pointer to input devmode buffer.
cbDevmode - size in bytes of full input devmode.
pPrivateDevmode - pointer to input private devmode buffer.
cbDrvPrivateSize - size in bytes of private devmode.
pDataSettings - Pointer to data structure defined by a template argument to be updated.
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
virtual HRESULT
GetPTDataSettingsFromDM(
_In_ PDEVMODE pDevmode,
_In_ ULONG cbDevmode,
_In_ PVOID pPrivateDevmode,
_In_ ULONG cbDrvPrivateSize,
_Out_ _T* pDataSettings
) = 0;
/*++
Routine Name:
MergePTDataSettingsWithPT
Routine Description:
This pure virtual function ensures the concrete feature converter class
implements a means of merging the data type defined by that class from
the PrintTicket settings.
Arguments:
pPrintTicket - Pointer to the PrintTicket to merge the data structure with.
pDataSettings - Pointer to data structure defined by a template argument to be updated.
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
virtual HRESULT
MergePTDataSettingsWithPT(
_In_ IXMLDOMDocument2* pPrintTicket,
_Inout_ _T* pDrvSettings
) = 0;
/*++
Routine Name:
SetPTDataInDM
Routine Description:
This pure virtual function ensures the concrete feature converter class
implements a means of setting the data type defined by that class in the
DevMode.
Arguments:
dataSettings - const reference to the data structure defined by a template argument to be update from.
pDevmode - pointer to input devmode buffer.
cbDevmode - size in bytes of full input devmode.
pPrivateDevmode - pointer to input private devmode buffer.
cbDrvPrivateSize - size in bytes of private devmode.
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
virtual HRESULT
SetPTDataInDM(
_In_ CONST _T& dataSettings,
_Inout_ PDEVMODE pDevmode,
_In_ ULONG cbDevmode,
_Inout_ PVOID pPrivateDevmode,
_In_ ULONG cbDrvPrivateSize
) = 0;
/*++
Routine Name:
SetPTDataInPT
Routine Description:
This pure virtual function ensures the concrete feature converter class
implements a means of setting the data type defined by that class in the
PrintTicket.
Arguments:
dataSettings - const reference to the data structure defined by a template argument to be update from.
pPrintTicket - Pointer to the PrintTicket to update the data structure with.
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
virtual HRESULT
SetPTDataInPT(
_In_ CONST _T& dataSettings,
_Inout_ IXMLDOMDocument2* pPrintTicket
) = 0;
/*++
Routine Name:
GetOptionFromGPDString
Routine Description:
This template function takes as a template parameter the type of the
data to be retrieved from the DevMode. A table is passed through that
provides the look-up between the GPD string and the data type to be
returned. The routine then iterates through the options for the feature
specified matching against look-up and returning the corresponding value.
Arguments:
pDevmode - pointer to input DevMode.
cbDevmode - count of bytes in the input devmode.
pszFeature - string defining the feature name to match against.
pOptTable - pointer to the look-up table matching the GPD option strings to the option value.
cOptEntries - the number of entries in the look-up table
result - reference to the result value to be updated (type defined by the template argument)
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
template<typename _U>
HRESULT
GetOptionFromGPDString(
_In_ PDEVMODE pDevmode,
_In_ ULONG cbDevmode,
_In_z_ PCSTR pszFeature,
_In_ CONST GPDStringToOption<_U>* pOptTable,
_In_ CONST UINT cOptEntries,
_Out_ _U& result
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pDevmode, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pszFeature, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pOptTable, E_POINTER)))
{
if (cbDevmode < sizeof(DEVMODE))
{
hr = E_INVALIDARG;
}
}
if (SUCCEEDED(hr))
{
BOOL bFound = FALSE;
if (cOptEntries > 0)
{
PCSTR pszOption = NULL;
if (SUCCEEDED(hr = m_pCoreHelper->GetOption(pDevmode, cbDevmode, pszFeature, &pszOption)))
{
CStringXDA cstrOption(pszOption);
for (UINT index = 0; index < cOptEntries && !bFound; index++)
{
if (cstrOption == pOptTable->pszOption)
{
result = pOptTable->option;
bFound = TRUE;
}
else
{
pOptTable++;
}
}
}
}
if (!bFound)
{
hr = E_ELEMENT_NOT_FOUND;
}
}
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
SetGPDStringFromOption
Routine Description:
This template function takes as a template parameter the type of the
data to be set in the DevMode. A table is passed through that provides
the look-up between the GPD string and the data type to be set. The routine
then iterates through the options for the feature specified matching against
the look-up and setting the corresponding value in the DevMode.
Arguments:
pDevmode - pointer to input DevMode.
cbDevmode - count of bytes in the input devmode.
pszFeature - string defining the feature name to match against.
pOptTable - pointer to the look-up table matching the GPD option strings to the option value.
cOptEntries - the number of entries in the look-up table
result - const reference to the result value to update from (type defined by the template argument)
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
template<typename _U>
HRESULT
SetGPDStringFromOption(
_Inout_ PDEVMODE pDevmode,
_In_ ULONG cbDevmode,
_In_z_ PCSTR pszFeature,
_In_ CONST GPDStringToOption<_U>* pOptTable,
_In_ CONST UINT cOptEntries,
_In_ CONST _U& option
)
{
HRESULT hr = S_OK;
if (SUCCEEDED(hr = CHECK_POINTER(pDevmode, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pszFeature, E_POINTER)) &&
SUCCEEDED(hr = CHECK_POINTER(pOptTable, E_POINTER)))
{
if (cbDevmode < sizeof(DEVMODE))
{
hr = E_INVALIDARG;
}
}
if (SUCCEEDED(hr))
{
if (cOptEntries > 0)
{
for (UINT index = 0; index < cOptEntries; index++)
{
if (option == pOptTable->option)
{
PRINT_FEATURE_OPTION featureOption[1] = {
pszFeature,
pOptTable->pszOption
};
DWORD dwResult = 0;
DWORD cPairsWritten = 0;
hr = m_pCoreHelper->SetOptions(pDevmode, cbDevmode, TRUE, featureOption, 1, &cPairsWritten, &dwResult);
break;
}
else
{
pOptTable++;
}
}
}
}
ERR_ON_HR(hr);
return hr;
}
protected:
CComPtr<IPrintCoreHelperUni> m_pCoreHelper;
};
|