internal void GetInfoComplete(IntPtr handle) { try { char[] buffer = new char[128]; _manufacturer = NativeMethods.HidD_GetManufacturerString(handle, buffer, 256) ? NativeMethods.NTString(buffer) : ""; _productName = NativeMethods.HidD_GetProductString(handle, buffer, 256) ? NativeMethods.NTString(buffer) : ""; _serialNumber = NativeMethods.HidD_GetSerialNumberString(handle, buffer, 256) ? NativeMethods.NTString(buffer) : ""; IntPtr preparsed; if (NativeMethods.HidD_GetPreparsedData(handle, out preparsed)) { NativeMethods.HIDP_CAPS caps; int statusCaps = NativeMethods.HidP_GetCaps(preparsed, out caps); if (statusCaps == NativeMethods.HIDP_STATUS_SUCCESS) { _maxInput = caps.InputReportByteLength; _maxOutput = caps.OutputReportByteLength; _maxFeature = caps.FeatureReportByteLength; } NativeMethods.HidD_FreePreparsedData(preparsed); } } finally { NativeMethods.CloseHandle(handle); } lock (_completeSync) { _complete = true; Monitor.PulseAll(_completeSync); } }
void RequiresGetInfo(GetInfoFlags flags) { lock (_getInfoLock) { flags &= ~_getInfoFlags; // Remove flags we already have. if (flags == 0) { return; } if (!TryOpenToGetInfo(handle => { if ((flags & GetInfoFlags.Manufacturer) != 0) { if (!TryGetDeviceString(handle, NativeMethods.HidD_GetManufacturerString, out _manufacturer)) { return(false); } } if ((flags & GetInfoFlags.ProductName) != 0) { if (!TryGetDeviceString(handle, NativeMethods.HidD_GetProductString, out _productName)) { return(false); } } if ((flags & GetInfoFlags.SerialNumber) != 0) { if (!TryGetDeviceString(handle, NativeMethods.HidD_GetSerialNumberString, out _serialNumber)) { return(false); } } if ((flags & GetInfoFlags.ReportInfo) != 0) { IntPtr preparsed; if (!NativeMethods.HidD_GetPreparsedData(handle, out preparsed)) { return(false); } try { NativeMethods.HIDP_CAPS caps; int statusCaps = NativeMethods.HidP_GetCaps(preparsed, out caps); if (statusCaps != NativeMethods.HIDP_STATUS_SUCCESS) { return(false); } _maxInput = caps.InputReportByteLength; _maxOutput = caps.OutputReportByteLength; _maxFeature = caps.FeatureReportByteLength; try { _reportDescriptor = new ReportDescriptorReconstructor().Run(preparsed, caps); } catch (NotImplementedException) { _reportDescriptor = null; } catch { return(false); } } finally { NativeMethods.HidD_FreePreparsedData(preparsed); } } return(true); })) { throw DeviceException.CreateIOException(this, "Failed to get info."); } _getInfoFlags |= flags; } }