Exemplo n.º 1
0
 /// <summary>
 /// Opens device
 /// </summary>
 /// <param name="DeviceName">fullpath to the device</param>
 /// <returns>-1 on error, handle otherwise</returns>
 public int CreateFile(string DeviceName)
 {
     HidHandle = DllImports.CreateFile(DeviceName,
                                       DllImports.GENERIC_READ | DllImports.GENERIC_WRITE,
                                       DllImports.FILE_SHARE_READ | DllImports.FILE_SHARE_WRITE,
                                       0, DllImports.OPEN_EXISTING, 0, 0);
     return((HidHandle == -1) ? 0 : 1);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Gets class devs
 /// </summary>
 /// <returns>Handle to the device info object</returns>
 public int SetupDiGetClassDevs()
 {
     DllImports.HidD_GetHidGuid(ref _guid);
     hDevInfo = DllImports.SetupDiGetClassDevs(ref _guid,
                                               IntPtr.Zero,
                                               IntPtr.Zero,
                                               DllImports.DIGCF_INTERFACEDEVICE | DllImports.DIGCF_PRESENT);
     return(hDevInfo);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Closes device
 /// </summary>
 public int CloseFile()
 {
     if (HidHandle != -1)
     {
         DllImports.CloseHandle(HidHandle);
         HidHandle = -1;
     }
     return(1);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Gets device interface detail
        /// </summary>
        public int SetupDiGetDeviceInterfaceDetail(ref int requiredSize, int deviceInterfaceDetailDataSize)
        {
            int retVal = DllImports.SetupDiGetDeviceInterfaceDetail(
                hDevInfo,
                ref _deviceInterfaceData,
                IntPtr.Zero,
                deviceInterfaceDetailDataSize,
                ref requiredSize,
                IntPtr.Zero);

            return(retVal);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Enumerates device interfaces
        /// </summary>
        public int SetupDiEnumDeviceInterfaces(int memberIndex)
        {
            _deviceInterfaceData        = new DllImports.SP_DEVICE_INTERFACE_DATA();
            _deviceInterfaceData.cbSize = Marshal.SizeOf(_deviceInterfaceData);
            int retVal = DllImports.SetupDiEnumDeviceInterfaces(
                hDevInfo,
                0,
                ref _guid,
                memberIndex,
                ref _deviceInterfaceData);

            return(retVal);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Reads data from the device
        /// </summary>
        public byte[] ReadFile(int inputReportByteLength)
        {
            int bytesRead = 0;

            byte[] inBuffer = new byte[inputReportByteLength];
            if (DllImports.ReadFile(HidHandle, inBuffer, inputReportByteLength, ref bytesRead, IntPtr.Zero))
            {
                byte[] outBuffer = new byte[bytesRead];
                Array.Copy(inBuffer, outBuffer, bytesRead);
                return(outBuffer);
            }

            return(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets device interface detail
        /// </summary>
        public int SetupDiGetDeviceInterfaceDetailEx(ref int requiredSize, int deviceInterfaceDetailDataSize)
        {
            _deviceInterfaceDetailData = new DllImports.PSP_DEVICE_INTERFACE_DETAIL_DATA {
                cbSize = 5
            };

            int retVal = DllImports.SetupDiGetDeviceInterfaceDetail(
                hDevInfo,
                ref _deviceInterfaceData,
                ref _deviceInterfaceDetailData,
                deviceInterfaceDetailDataSize,
                ref requiredSize,
                IntPtr.Zero);

            DevicePathName = _deviceInterfaceDetailData.DevicePath;
            return(retVal);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a duplicate of the handle
        /// </summary>
        public IntPtr DuplicateHandle(IntPtr sourceHandle)
        {
            IntPtr newHandle;

            IntPtr currentProcess = DllImports.GetCurrentProcess();
            bool   result         = DllImports.DuplicateHandle(
                currentProcess,
                sourceHandle,
                currentProcess,
                out newHandle,
                0,
                false,
                DllImports.DUPLICATE_SAME_ACCESS);

            if (!result)
            {
                return(IntPtr.Zero);
            }

            return(newHandle);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Cancels synchronous io
 /// </summary>
 public void CancelSynchronousIo(IntPtr threadHandle)
 {
     DllImports.CancelSynchronousIo(threadHandle);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Destroys the device info list
 /// </summary>
 public int SetupDiDestroyDeviceInfoList()
 {
     return(DllImports.SetupDiDestroyDeviceInfoList(hDevInfo));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Frees parsed data
 /// </summary>
 public int InteropFreePreparsedData(int pPHIDP_PREPARSED_DATA)
 {
     return(DllImports.SetupDiDestroyDeviceInfoList(pPHIDP_PREPARSED_DATA));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Gets raw data
 /// </summary>
 public int GetPreparsedData(int hObject, ref int preParsedData)
 {
     return(DllImports.HidD_GetPreparsedData(hObject, ref preParsedData));
 }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the current thread handle
        /// </summary>
        public IntPtr GetCurrentThreadHandle()
        {
            IntPtr handle = DllImports.GetCurrentThread();

            return(DuplicateHandle(handle));
        }
Exemplo n.º 14
0
 /// <summary>
 /// Gets HID caps
 /// </summary>
 public int GetCaps(int preParsedData)
 {
     HidCaps = new DllImports.HIDP_CAPS();
     return(DllImports.HidP_GetCaps(preParsedData, ref HidCaps));
 }