Are there any examples how to scan with an C++ WIA2 application on Windows7? Because the only thing I got working so far with the poor documentation is calling the GetImageDlg method from IWiaDevMgr2. But I want to select a scanning device first and than call DeviceDlg from the IWiaItem2 or scan without calling the standard Dialog at all.
DeviceDlg allways throws E_INVALIDARG for some unknown reason and I have no clue how to do it without calling it.
So any help would be appreciated.
- Moved by Jesse Jiang Wednesday, March 06, 2013 3:06 AM
Based on your description, I’d like to move this thread to a more suitable forum: Windows Desktop SDK.
Thanks for your understanding.
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
To select a device, use IWiaDevMgr::SelectDeviceDlg with StiDeviceTypeScanner. You will get a device id (can be used to pre-select a device in the next run) and a pointer to the root item exposed by the driver's WIA implementation.
The root item then can be used to show a scanning UI via DeviceDlg, good for previewing, changing settings like DPI and how many pictures are scanned at once for feeder type scanners. If you don't want to show the UI, QI the root item or the tree item that represents the type or scanner you want for IWiaPropertyStorage then change settings using values that you gathered in a previous scanning session. The property ids are documented in the WDK, but it seems Xp and Vista drivers have different property ids and tree structures. Of course a driver can implement both set of property ids for backward compatibility, or have bug in the property implementations that you may not expect.
You can then QI IWiaTransfer from the desired scanner in the WIA tree to begin the scanning. Or you can issue a WIA_CMD_TAKE_PICTURE device command via IWiaItem2::DeviceCommand then wait for the WIA_EVENT_ITEM_CREATED events for each picture from the feeder, before QI IWiaTransfer or each item created by a WIA_DPS_PAGES setting) .
- Edited by Sheng Jiang 蒋晟MVP Saturday, March 09, 2013 4:03 PM
I had same error when I used WIA. The problem was in incorrect using strings, passed to GetImageDlg. Strings must be allocated with SysAllocString function. You can use CComBSTR that does it automaticaly
pWiaDevMgr->GetImageDlg(NULL, StiDeviceTypeScanner, WIA_DEVICE_DIALOG_SINGLE_IMAGE, WIA_INTENT_NONE, NULL, CComBSTR(L"D:\\temp\\1.png"), &guid)