コード例 #1
0
        internal void Init(string path, WinHidDevice device)
        {
            IntPtr handle = NativeMethods.CreateFileFromDevice(path, NativeMethods.EFileAccess.Read | NativeMethods.EFileAccess.Write, NativeMethods.EFileShare.All);

            if (handle == (IntPtr)(-1))
            {
                throw new IOException("Unable to open HID class device.");
            }

            _device = device;
            _handle = handle;
            HandleInitAndOpen();
        }
コード例 #2
0
ファイル: WinHidManager.cs プロジェクト: mikesocha3/Socha3
        protected override bool TryCreateDevice(object key, out HidDevice device, out object completionState)
        {
            string path = (string)key; var hidDevice = new WinHidDevice(path);
            IntPtr handle = NativeMethods.CreateFileFromDevice(path, NativeMethods.EFileAccess.None, NativeMethods.EFileShare.All);

            device = null; completionState = null; if (handle == (IntPtr)(-1))
            {
                return(false);
            }

            bool ok = false;

            try { ok = hidDevice.GetInfo(handle); } catch { }
            if (!ok)
            {
                NativeMethods.CloseHandle(handle); return(false);
            }

            device = hidDevice; completionState = handle;
            return(true);
        }