Пример #1
0
        /// <summary>
        /// Retrieves a feature from the device.
        /// </summary>
        /// <param name="device"></param>
        /// <param name="code"></param>
        /// <param name="datalen"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static HIDFeatureResult GetHIDFeature(IntPtr device, int code, int datalen = 16)
        {
            HIDFeatureResult GetHIDFeatureRet = default;
            MemPtr           mm = new MemPtr();

            int i = code;

            try
            {
                mm.AllocZero(datalen);
                mm.ByteAt(0L) = (byte)i;
                if (UsbLibHelpers.HidD_GetFeature(device, mm.Handle, (int)mm.Length))
                {
                    GetHIDFeatureRet = new HIDFeatureResult(i, mm);
                }
                else
                {
                    GetHIDFeatureRet = null;
                }

                mm.Free();
            }
            catch
            {
                mm.Free();
                return(null);
            }

            return(GetHIDFeatureRet);
        }
Пример #2
0
        /// <summary>
        /// Creates the window.
        /// </summary>
        /// <param name="buffLen">Optional length of the file system changes buffer.</param>
        /// <returns>True if successful.</returns>
        private bool internalCreate(int buffLen = DefaultBufferSize)
        {
            if (buffLen < 1024)
            {
                throw new ArgumentException("Buffer length cannot be smaller than 1k.");
            }

            try
            {
                var cp = new CreateParams();
                if (_owner != IntPtr.Zero)
                {
                    cp.Style  = User32.WS_CHILDWINDOW;
                    cp.Parent = _owner;
                }

                CreateHandle(cp);
            }
            catch
            {
                return(false);
            }

            // 128k is definitely enough when the thread is running continuously.
            // barring something funky blocking us ...
            return(_Buff.AllocZero(buffLen, true));
        }