forked from GLDsuh-a/qt-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WiaWrap.h
544 lines (395 loc) · 14.1 KB
/
WiaWrap.h
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
/*
Copyright (c) Microsoft Corporation. All rights reserved.
--*/
#ifndef __WIAWRAP__
#define __WIAWRAP__
namespace WiaWrap
{
//////////////////////////////////////////////////////////////////////////
//
// ProgressCallback
//
/*
The ProgressCallback function is an application-defined callback function
used with the WiaGetImage function.
HRESULT
CALLBACK
ProgressCallback(
LONG lStatus,
LONG lPercentComplete,
PVOID pParam
);
Parameters
lStatus
[in] Specifies a constant that indicates the status of the WIA device.
Can be set to one of the following values;
IT_STATUS_TRANSFER_FROM_DEVICE: Data is currently being
transferred from the WIA device.
IT_STATUS_PROCESSING_DATA: Data is currently being processed.
IT_STATUS_TRANSFER_TO_CLIENT: Data is currently being transferred
to the client's data buffer.
lPercentComplete
[in] Specifies the percentage of the total data that has been
transferred so far.
pParam
[in] Specifies the application-defined value given in WiaGetImage
Return Values
To continue the data transfer, return S_OK.
To cancel the data transfer, return S_FALSE.
If the method fails, return a standard COM error code.
--*/
typedef HRESULT (CALLBACK *PFNPROGRESSCALLBACK)(
LONG lStatus,
LONG lPercentComplete,
PVOID pParam
);
//////////////////////////////////////////////////////////////////////////
//
// WiaGetImage
//
/*
The WiaGetImage function displays one or more dialog boxes that enable a
user to acquire multiple images from a WIA device and return them in an
array of IStream interfaces. This method combines the functionality of
SelectDeviceDlg, DeviceDlg and idtGetBandedData API's to completely
encapsulate image acquisition within a single function call.
HRESULT
WiaGetImage(
HWND hWndParent,
LONG lDeviceType,
LONG lFlags,
LONG lIntent,
IWiaDevMgr *pSuppliedWiaDevMgr,
IWiaItem *pSuppliedItemRoot,
PFNPROGRESSCALLBACK pfnProgressCallback,
PVOID pProgressCallbackParam,
GUID *pguidFormat,
LONG *plCount,
IStream ***pppStream
);
Parameters
hwndParent
[in] Handle of the window that will own the dialog boxes.
lDeviceType
[in] Specifies which type of WIA device to use. Can be set to one of
the following values;
StiDeviceTypeDefault
StiDeviceTypeScanner
StiDeviceTypeDigitalCamera
StiDeviceTypeStreamingVideo
lFlags
[in] Specifies dialog box behavior. Can be set to any combination of
the following values;
0: Default behavior.
WIA_SELECT_DEVICE_NODEFAULT: Force this method to display the
Select Device dialog box. If this flag is not present, and if
WiaGetImage finds only one matching device, it will not display
the Select Device dialog box.
WIA_DEVICE_DIALOG_SINGLE_IMAGE: Restrict image selection to a
single image in the device image acquisition dialog box.
WIA_DEVICE_DIALOG_USE_COMMON_UI: Use the system UI, if available,
rather than the vendor-supplied UI. If the system UI is not
available, the vendor UI is used. If neither UI is available,
the function returns E_NOTIMPL.
lIntent
[in] Specifies what type of data the image is intended to represent.
pSuppliedWiaDevMgr
[in] Pointer to the interface of the WIA device manager. This
interface is used when WiaGetImage displays the Select Device dialog
box. If the application passes NULL for this parameter, WiaGetImage
connects to the local WIA device manager.
pSuppliedItemRoot
[in] Pointer to the interface of the hierarchical tree of IWiaItem
objects. If the application passes NULL for this parameter,
WiaGetImage displays the Select Device dialog box that lets the user
select the WIA input device. If the application specifies a WIA input
device by passing a valid pointer to the device's item tree for this
parameter, WiaGetImage does not display the Select Device dialog box,
instead, it will use the specified input device to acquire the image.
pfnProgressCallback
[in] Specifies the address of a callback function of type
PFNPROGRESSCALLBACK that is called periodically to provide data
transfer status notifications. If the application passes NULL
for this parameter, WiaGetImage displays a simple progress dialog
with a status message, a progress bar and a cancel button. If the
application passes a valid function, WiaGetImage does not display
this progress dialog, instead, it calls the specified function with
the status message and the completion percentage values.
pProgressCallbackParam
[in] Specifies an argument to be passed to the callback function.
The value of the argument is specified by the application. This
parameter can be NULL.
pguidFormat
[in, out] On input, contains a pointer to a GUID that specifies the
format to use. On output, holds the format used. If the application
passes GUID_NULL for this parameter, WiaGetImage uses the default
transfer format of the device and returns this format. If the
application passes NULL for this parameter, WiaGetImage uses the
default transfer format of the device but it does not return the
used format.
plCount
[out] Receives the number of items in the array indicated by the
pppStream parameter.
pppStream
[out] Receives the address of an array of pointers to IStream
interfaces. Applications must call the IStream::Release method
for each element in the array of interface pointers they receive.
Applications must also free the pppStream array itself using
CoTaskMemFree.
Return Values
WiaGetImage returns one of the following values or a standard COM error
if it fails for any other reason.
S_OK: if the data is transferred successfully.
S_FALSE: if the user cancels one of the device selection, image selection
or image transfer dialog boxes.
WIA_S_NO_DEVICE_AVAILABLE: if no WIA device is currently available.
E_NOTIMPL: if no UI is available.
Remarks
WiaGetImage returns the transferred images as stream objects in the
pppStream array parameter. The array is created with CoTaskMemAlloc
and the stream objects are created with CreateStreamOnHGlobal. The array
will contain a single entry if the WIA_DEVICE_DIALOG_SINGLE_IMAGE flag
is specified. Otherwise, it may contain one or more entries and the
count will be returned in the plCount parameter.
The stream object will contain the image data. To create a GDI image
object from the stream object, use the Gdiplus::Image(IStream* stream)
function. To obtain a pointer to the memory address of the data, use
the GetHGlobalFromStream API to obtain an HGLOBAL and use GlobalLock
to obtain a direct pointer to the data.
--*/
HRESULT
WiaGetImage(
HWND hWndParent,
LONG lDeviceType,
LONG lFlags,
LONG lIntent,
IWiaDevMgr *pSuppliedWiaDevMgr,
IWiaItem *pSuppliedItemRoot,
PFNPROGRESSCALLBACK pfnProgressCallback,
PVOID pProgressCallbackParam,
GUID *pguidFormat,
LONG *plCount,
IStream ***pppStream
);
//////////////////////////////////////////////////////////////////////////
//
// WiaGetNumDevices
//
/*
The WiaGetNumDevices function returns the number of WIA devices on
the system.
HRESULT
WiaGetNumDevices(
IWiaDevMgr *pSuppliedWiaDevMgr,
ULONG *pulNumDevices
);
Parameters
pSuppliedWiaDevMgr
[in] Pointer to the interface of the WIA device manager. If the
application passes NULL for this parameter, WiaGetNumDevices
connects to the local WIA device manager.
pulNumDevices
[out] Receives the number of WIA devices on the system.
Return Values
WiaGetNumDevices returns S_OK on success or a standard COM error
if it fails for any reason.
--*/
HRESULT
WiaGetNumDevices(
IWiaDevMgr *pSuppliedWiaDevMgr,
ULONG *pulNumDevices
);
//////////////////////////////////////////////////////////////////////////
//
// ReadPropertyLong
//
/*
The ReadPropertyLong function reads a long integer value from a WIA
property storage
HRESULT
ReadPropertyLong(
IWiaPropertyStorage *pWiaPropertyStorage,
const PROPSPEC *pPropSpec,
LONG *plResult
);
Parameters
pWiaPropertyStorage
[in] Pointer to the interface of the WIA property storage.
PropSpec
[in] Pointer to a PROPSPEC structure that specifies which
property is to be read.
plResult
[out] Receives the value of the property specified by PropSpec
Return Values
ReadPropertyLong returns S_OK on success or a standard COM error
if it fails for any reason.
--*/
HRESULT
ReadPropertyLong(
IWiaPropertyStorage *pWiaPropertyStorage,
const PROPSPEC *pPropSpec,
LONG *plResult
);
//////////////////////////////////////////////////////////////////////////
//
// ReadPropertyGuid
//
/*
The ReadPropertyGuid function reads a GUID value from a WIA property
storage
HRESULT
ReadPropertyGuid(
IWiaPropertyStorage *pWiaPropertyStorage,
const PROPSPEC *pPropSpec,
GUID *pguidResult
);
Parameters
pWiaPropertyStorage
[in] Pointer to the interface of the WIA property storage.
pPropSpec
[in] Pointer to a PROPSPEC structure that specifies which
property is to be read.
plResult
[out] Receives the value of the property specified by PropSpec
Return Values
ReadPropertyGuid returns S_OK on success or a standard COM error
if it fails for any reason.
--*/
HRESULT
ReadPropertyGuid(
IWiaPropertyStorage *pWiaPropertyStorage,
const PROPSPEC *pPropSpec,
GUID *pguidResult
);
//////////////////////////////////////////////////////////////////////////
//
// CComPtrArray
//
/*
CComPtrArray stores an array of COM interface pointers and performs
reference counting through AddRef and Release methods.
CComPtrArray can be used with WiaGetImage and DeviceDlg functions
to provide automatic deallocation of the output arrays.
Methods
CComPtrArray()
Initializes the array pointer and the count to zero.
CComPtrArray(int nCount)
Allocates the array for with CoTaskMemAlloc for nCount items and
initializes the interface pointers to NULL
Copy(const CComPtrArray& rhs)
Allocates a new array with CoTaskMemAlloc, copies the interface
pointers and call AddRef() on the copied pointers.
Clear()
Calls Release on the interface pointers in the array and
deallocates the array with CoTaskMemFree
CComPtrArray(const CComPtrArray& rhs)
Calls the Copy method to copy the new contents.
CComPtrArray &operator =(const CComPtrArray& rhs)
Calls the Clear method to delete the current contents and calls
the Copy method to copy the new contents.
~CComPtrArray()
Destructor, calls the Clear method
operator T **()
Returns the dereferenced value of the member pointer.
bool operator!()
Returns TRUE or FALSE, depending on whether the member pointer is
NULL or not.
T ***operator&()
Returns the address of the member pointer.
LONG &Count()
Returns a reference to the count.
--*/
template <class T>
class CComPtrArray
{
public:
CComPtrArray()
{
m_pArray = NULL;
m_nCount = 0;
}
explicit CComPtrArray(int nCount)
{
m_pArray = (T **) CoTaskMemAlloc(nCount * sizeof(T *));
m_nCount = m_pArray == NULL ? 0 : nCount;
for (int i = 0; i < m_nCount; i)
{
m_pArray[i] = NULL;
}
}
CComPtrArray(const CComPtrArray& rhs)
{
Copy(rhs);
}
~CComPtrArray()
{
Clear();
}
CComPtrArray &operator =(const CComPtrArray& rhs)
{
if (this != &rhs)
{
Clear();
Copy(rhs);
}
return *this;
}
operator T **()
{
return m_pArray;
}
bool operator!()
{
return m_pArray == NULL;
}
T ***operator&()
{
return &m_pArray;
}
LONG &Count()
{
return m_nCount;
}
void Clear()
{
if (m_pArray != NULL)
{
for (int i = 0; i < m_nCount; i)
{
if (m_pArray[i] != NULL)
{
m_pArray[i]->Release();
}
}
CoTaskMemFree(m_pArray);
m_pArray = NULL;
m_nCount = 0;
}
}
void Copy(const CComPtrArray& rhs)
{
m_pArray = NULL;
m_nCount = 0;
if (rhs.m_pArray != NULL)
{
m_pArray = (T**) CoTaskMemAlloc(rhs.m_nCount * sizeof(T *));
if (m_pArray != NULL)
{
m_nCount = rhs.m_nCount;
for (int i = 0; i < m_nCount; i)
{
m_pArray[i] = rhs.m_pArray[i];
if (m_pArray[i] != NULL)
{
m_pArray[i]->AddRef();
}
}
}
}
}
private:
T **m_pArray;
LONG m_nCount;
};
}; // namespace WiaWrap
#endif //__WIAWRAP__