"The process cannot access the file because it is being used by another process.HRESULT0x80070020”. Error Connecting to Barcode Scanner using c# app

0

I have an c# application that connects to the barcode scanners that are in HID mode by using the devices VendorID(VID) and ProductID(PID). Using the devices VID and PID we will construct the device path and they we will call the below code to create a Kernel object File so that we will get the handle to the device.

// Allocate a file object in the kernel, then return a handle to it.
    [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
    protected extern static SafeFileHandle CreateFile(String DevicePath,
    uint dwDesiredAccess, System.IO.FileShare dwShareMode,
    IntPtr securityAttrs_MustBeZero, System.IO.FileMode dwCreationDisposition,
    uint dwFlagsAndAttributes, IntPtr hTemplateFile_MustBeZero);

The above code works for most of the Barcode scanners except the Zebra DS457 scanner The above line of code is throwing β€œThe process cannot access the file because it is being used by another process. HRESULT 0x80070020” error only when trying to connect to the Zebra DS457 scanner. I am not sure why this is happening only for this scanner. Any suggestions on this is highly appreciated.

c#
kernel
barcode-scanner
asked on Stack Overflow Jan 28, 2021 by Devd

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0