public static HidpCaps HidP_GetCaps(SafePreparsedDataHandle preparsedData) { var hidCaps = default(HidpCaps); var result = HidP_GetCaps(preparsedData, ref hidCaps); switch (result.Value) { case NTStatus.Code.HIDP_STATUS_SUCCESS: return hidCaps; case NTStatus.Code.HIDP_STATUS_INVALID_PREPARSED_DATA: throw new ArgumentException("The specified preparsed data is invalid.", nameof(preparsedData)); default: result.ThrowOnError(); throw new InvalidOperationException("HidP_GetCaps returned an unexpected success value"); } }
public static HidpCaps HidP_GetCaps(SafePreparsedDataHandle preparsedData) { var hidCaps = default(HidpCaps); var result = HidP_GetCaps(preparsedData, ref hidCaps); switch (result.Value) { case NTStatus.Code.HIDP_STATUS_SUCCESS: return(hidCaps); case NTStatus.Code.HIDP_STATUS_INVALID_PREPARSED_DATA: throw new ArgumentException("The specified preparsed data is invalid.", nameof(preparsedData)); default: result.ThrowOnError(); throw new InvalidOperationException("HidP_GetCaps returned an unexpected success value"); } }
/// <summary> /// Returns the pressed buttons from the input report /// </summary> /// <param name="inputReport">An input report</param> /// <returns></returns> public short[] GetButtonUsages(byte[] inputReport) { if (inputReport.Length != capabilities.InputReportByteLength) { throw new ArgumentException("Report length does not match capabilities report length", nameof(inputReport)); } using (SafePreparsedDataHandle preparsedData = HidMethods.GetPreparsedData(this.handle)) { var inputButtonCapCount = capabilities.NumberInputButtonCaps; HidButtonCaps[] buttonCaps = new HidButtonCaps[inputButtonCapCount]; var buttonCount = buttonCaps[0].Range.UsageMax - buttonCaps[0].Range.UsageMin + 1; short[] usages = new short[buttonCount]; int reportLength = capabilities.InputReportByteLength; byte[] data = new byte[reportLength]; var ret = HidMethods.GetUsages( (int)HidMethods.HID_REPORT_TYPE.HidP_Input, buttonCaps[0].UsagePage, 0, usages, ref buttonCount, preparsedData, data, reportLength); if (ret != HidpStatus.HIDP_STATUS_SUCCESS) { throw new Exception("Failed to parse input report", new Win32Exception(Marshal.GetLastWin32Error())); } return(usages); } }
public static extern NTSTATUS HidP_GetCaps(SafePreparsedDataHandle preparsedData, ref HidpCaps capabilities);
public static extern bool HidD_GetPreparsedData( SafeObjectHandle hidDeviceObject, out SafePreparsedDataHandle preparsedDataHandle);
/// <summary> /// Returns a top-level collection's <see cref="HidpCaps" /> structure. /// </summary> /// <param name="preparsedData">Pointer to a top-level collection's preparsed data.</param> /// <param name="capabilities"> /// Pointer to a caller-allocated buffer that the routine uses to return a collection's /// <see cref="HidpCaps" /> structure. /// </param> /// <returns> /// <see cref="NTStatus.HIDP_STATUS_SUCCESS" /> on success or <see cref="NTStatus.HIDP_STATUS_INVALID_PREPARSED_DATA" /> if rhe /// specified preparsed data is invalid. /// </returns> public NTStatus InvokeHidP_GetCaps(SafePreparsedDataHandle preparsedData, ref HidpCaps capabilities) => HidP_GetCaps(preparsedData, capabilities);
/// <summary> /// Returns a top-level collection's preparsed data. /// </summary> /// <param name="hidDeviceObject">Specifies an open handle to a top-level collection.</param> /// <param name="preparsedDataHandle"> /// Pointer to the address of a routine-allocated buffer that contains a collection's /// preparsed data in a <see cref="SafePreparsedDataHandle" /> structure. /// </param> /// <returns>TRUE if it succeeds; otherwise, it returns FALSE.</returns> public bool InvokeHidD_GetPreparsedData( SafeObjectHandle hidDeviceObject, out SafePreparsedDataHandle preparsedDataHandle) => HidD_GetPreparsedData(hidDeviceObject, preparsedDataHandle);