none
Scan multiple pages with WIA in C# return HRESULT E_FAIL

    Question

  • Hello,

     

    I try to scan multiple pages with WIA in C# on Windows 10 64 bit Build 17763, the first page work, but the scanner fails for second page and return an error "HRESULT E_FAIL" "System.Runtime.InteropServices.COMException (0x80004005)"

    WIA.CommonDialog dialog = new WIA.CommonDialog();
    Device device = dialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
    Items items = dialog.ShowSelectItems(device);
    foreach (Item item in items)
    {
    	while (true)
    	{
    		try
    		{
    			ImageFile image = (ImageFile)dialog.ShowTransfer(item);
    		}
    		catch (COMException ce)
    		{
    			Console.WriteLine(ce);
    		}
    	}
    }

    I tried with some scanners HP and I have the same problem.

    Thanks



    • Edited by pol9595 Friday, January 11, 2019 11:09 PM
    Friday, January 11, 2019 10:58 PM

All replies

  • Why do you have the "while(true)" in there?  After you have transferred an item, you probably don't want to transfer it again and again and again, which is what this code does.  You want to transfer each item once.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Saturday, January 12, 2019 1:52 AM
  • all examples in C# use while(true) for multiple pages scanning

    on stack overflow for example : "Scanning with WIA automatic feeder scanner fails for second page"

    I think Windows Image Acquisition (WIA) has a bug on Windows 10


    • Edited by pol9595 Saturday, January 12, 2019 5:48 PM
    Saturday, January 12, 2019 5:47 PM
  • Hi,

    From this thread, it seems like the ShowTransfer() method was unable to convert the page to .png or .tiff WHILE scanning. Try to set the format to JPEG or BMP to solve the issue:

        ImageFile image = (ImageFile)dialog.ShowTransfer(item, FormatJPEG, false);

    Also please refer to the following similar threads:

    Multipage WIA scan (docfeeder) scans 1 page and blocks scanner

    Scanning with WIA automatic feeder scanner fails for second page

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 14, 2019 6:24 AM
  • My code work when I choose in the "device selection dialog / Which device do you want to use?" :"HP scan driver", and doesn't work when I choose "WSD Scan Device".
    • Edited by pol9595 Tuesday, January 15, 2019 9:31 PM
    Tuesday, January 15, 2019 9:31 PM
  • My code work when I choose in the "device selection dialog / Which device do you want to use?" :"HP scan driver", and doesn't work when I choose "WSD Scan Device".

    Hi,

    Do you mean these two options are different options for the scanner?

    If so, I'm afraid this problem is more related to the scanner, please contact the provider for help.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 25, 2019 2:37 AM