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
|
/*++
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:
xdsmplcf.cpp
Abstract:
XPSDrv feature sample class factory implementation.
--*/
#include "precomp.h"
#include "debug.h"
#include "globals.h"
#include "xdexcept.h"
#include "xdstring.h"
#include "xdsmplcf.h"
#include "xdsmplui.h"
#include "xdsmplptprov.h"
/*++
Routine Name:
CXDSmplUICF::CreateInstance
Routine Description:
Creates an object of the specified CLSID and retrieves an interface pointer to this object.
The supported class objects are currently IPrintOemUI and IPrintOemPrintTicketProvider.
Arguments:
pUnkOuter - This must be NULL, as aggregare object creation is not supported.
riid - The IID of the requested interface.
ppvObject - A pointer to the interface pointer identified by riid.
If the object does not support this interface, ppvObj is set to NULL.
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CXDSmplUICF::CreateInstance(
_In_opt_ LPUNKNOWN pUnkOuter,
_In_ REFIID riid,
_Outptr_ PVOID* ppvObject
)
{
HRESULT hr = S_OK;
if (ppvObject == NULL)
{
hr = E_POINTER;
goto Exit;
}
*ppvObject = NULL;
if (pUnkOuter == NULL)
{
//
// Create UI component
//
CXDSmplUI* pXDSmplUI = NULL;
try
{
pXDSmplUI = new(std::nothrow) CXDSmplUI;
hr = CHECK_POINTER(pXDSmplUI, E_OUTOFMEMORY);
}
catch (CXDException& e)
{
hr = e;
}
catch (...)
{
hr = E_FAIL;
}
if (SUCCEEDED(hr))
{
//
// Get the requested interface
//
hr = pXDSmplUI->QueryInterface(riid, ppvObject) ;
//
// Release the IUnknown pointer. If QueryInterface failed
// the Release() call will clean up
//
pXDSmplUI->Release();
//
// If QueryInterface failed this could be a request for the
// PTProvider Interface
//
if (FAILED(hr))
{
CXDSmplPTProvider* pXDSmplPT = NULL;
try
{
pXDSmplPT = new(std::nothrow) CXDSmplPTProvider;
hr = CHECK_POINTER(pXDSmplPT, E_OUTOFMEMORY);
}
catch (CXDException& e)
{
_Analysis_assume_((*ppvObject) == NULL);
hr = e;
}
catch (...)
{
hr = E_FAIL;
}
if (SUCCEEDED(hr))
{
hr = pXDSmplPT->QueryInterface(riid, ppvObject) ;
//
// Release the IUnknown pointer.
// (If QueryInterface failed, component will delete itself.)
//
pXDSmplPT->Release();
}
}
}
}
else
{
//
// Cannot aggregate
//
hr = CLASS_E_NOAGGREGATION;
}
Exit:
ERR_ON_HR(hr);
return hr;
}
/*++
Routine Name:
CXDSmplUICF::LockServer
Routine Description:
Increments and decrements the UI Plug-in Module lock count.
Arguments:
bLock - If TRUE, the lock count is incremented; otherwise, the lock count is decremented.
Return Value:
HRESULT
S_OK - On success
E_* - On error
--*/
HRESULT
CXDSmplUICF::LockServer(
BOOL bLock
)
{
if (bLock)
{
InterlockedIncrement(&g_cServerLocks);
}
else
{
InterlockedDecrement(&g_cServerLocks);
}
return S_OK;
}
|