public IEnumerable <WiaDeviceInfo> GetDeviceInfos()
        {
            List <WiaDeviceInfo> result = new List <WiaDeviceInfo>();

            WiaException.Check(Version == WiaVersion.Wia10
                ? NativeWiaMethods.EnumerateDevices1(Handle, x => result.Add(new WiaDeviceInfo(Version, x)))
                : NativeWiaMethods.EnumerateDevices2(Handle, x => result.Add(new WiaDeviceInfo(Version, x))));
            return(result);
        }
Exemple #2
0
        public List <WiaItem> GetSubItems()
        {
            var items = new List <WiaItem>();

            WiaException.Check(Version == WiaVersion.Wia10
                ? NativeWiaMethods.EnumerateItems1(Handle, itemHandle => items.Add(new WiaItem(Version, itemHandle)))
                : NativeWiaMethods.EnumerateItems2(Handle, itemHandle => items.Add(new WiaItem(Version, itemHandle))));
            return(items);
        }
        public WiaDevice?PromptForDevice(IntPtr parentWindowHandle)
        {
            var hr = Version == WiaVersion.Wia10
                ? NativeWiaMethods.SelectDevice1(Handle, parentWindowHandle, SCANNER_DEVICE_TYPE, SELECT_DEVICE_NODEFAULT, out _, out var deviceHandle)
                : NativeWiaMethods.SelectDevice2(Handle, parentWindowHandle, SCANNER_DEVICE_TYPE, SELECT_DEVICE_NODEFAULT, out _, out deviceHandle);

            if (hr == 1)
            {
                return(null);
            }
            WiaException.Check(hr);
            return(new WiaDevice(Version, deviceHandle));;
        }
Exemple #4
0
        public bool Download()
        {
            var hr = Version == WiaVersion.Wia10
                ? NativeWiaMethods.Download1(Handle, TransferStatusCallback)
                : NativeWiaMethods.Download2(Handle, TransferStatusCallback);

            if (hr == 1)
            {
                // User cancelled
                return(false);
            }
            WiaException.Check(hr);
            return(true);
        }
        public string[]? PromptForImage(IntPtr parentWindowHandle, WiaDevice device, string?tempFolder = null)
        {
            tempFolder ??= Path.GetTempPath();
            var    fileName   = Path.GetRandomFileName();
            IntPtr itemHandle = IntPtr.Zero;
            int    fileCount  = 0;

            string[] filePaths = new string[0];
            var      hr        = Version == WiaVersion.Wia10
                ? NativeWiaMethods.GetImage1(Handle, parentWindowHandle, SCANNER_DEVICE_TYPE, 0, 0, Path.Combine(tempFolder, fileName), IntPtr.Zero)
                : NativeWiaMethods.GetImage2(Handle, 0, device.Id(), parentWindowHandle, tempFolder, fileName, ref fileCount, ref filePaths, ref itemHandle);

            if (hr == 1)
            {
                return(null);
            }
            WiaException.Check(hr);
            return(filePaths ?? new[] { Path.Combine(tempFolder, fileName) });
        }
Exemple #6
0
        public WiaItem?PromptToConfigure(IntPtr parentWindowHandle)
        {
            if (Version == WiaVersion.Wia20)
            {
                throw new InvalidOperationException("WIA 2.0 does not support PromptToConfigure. Use WiaDeviceManager.PromptForImage if you want to use the native WIA 2.0 UI.");
            }

            int itemCount = 0;

            IntPtr[]? items = null;
            var hr = NativeWiaMethods.ConfigureDevice1(Handle, parentWindowHandle, 0, 0, ref itemCount, ref items);

            if (hr == 1)
            {
                return(null);
            }
            WiaException.Check(hr);
            if (items == null)
            {
                return(null);
            }
            return(new WiaItem(Version, items[0]));
        }
 protected internal WiaPropertyCollection(WiaVersion version, IntPtr propertyStorageHandle) : base(version, propertyStorageHandle)
 {
     _propertyDict = new Dictionary <int, WiaProperty>();
     WiaException.Check(NativeWiaMethods.EnumerateProperties(Handle,
                                                             (id, name, type) => _propertyDict.Add(id, new WiaProperty(Handle, id, name, type))));
 }