예제 #1
0
        /// <summary>
        /// Attempts to get a USB configuration descriptor based on its index.
        /// </summary>
        /// <param name="configIndex">
        /// The index of the configuration you wish to retrieve
        /// </param>
        /// <param name="descriptor">
        /// The requested descriptor.
        /// </param>
        /// <returns>
        /// <see langword="true"/> if the descriptor could be loaded correctly; otherwise,
        /// <see langword="false" ">.
        /// </returns>
        public unsafe bool TryGetConfigDescriptor(byte configIndex, out UsbConfigInfo descriptor)
        {
            this.EnsureNotDisposed();

            ConfigDescriptor *list  = null;
            UsbConfigInfo     value = null;

            try
            {
                var ret = NativeMethods.GetConfigDescriptor(this.device, configIndex, &list);

                if (ret == Error.NotFound)
                {
                    descriptor = null;
                    return(false);
                }

                ret.ThrowOnError();

                value      = UsbConfigInfo.FromUsbConfigDescriptor(this, list[0]);
                descriptor = value;
                return(true);
            }
            finally
            {
                if (list != null)
                {
                    NativeMethods.FreeConfigDescriptor(list);
                }
            }
        }
예제 #2
0
 public static extern void FreeConfigDescriptor(ConfigDescriptor *config);