예제 #1
0
        public HidCapabilities GetCapabilities(SafeFileHandle handle)
        {
            if (handle == null)
            {
                throw new ArgumentNullException($"{nameof(handle)} is null");
            }

            IntPtr          preparsedData = IntPtr.Zero;
            HidCapabilities capabilities  = new HidCapabilities();

            var preParseResult = NativeMethods.HidD_GetPreparsedData(handle, ref preparsedData);

            if (!preParseResult)
            {
                throw new GetHidCapabilitiesException($"Could not get pre-parsed data by this {nameof(handle)}: {handle}");
            }

            bool isGetCaps = false;

            //HIDP_CAPS caps = new HIDP_CAPS();
            using (SafePreParsedDataHandle preParsedDataHandle = new SafePreParsedDataHandle(preparsedData, this))
            {
                var getCapResult = NativeMethods.HidP_GetCaps(preParsedDataHandle, capabilities);

                // Return value is HIDP_STATUS_SUCCESS or HIDP_STATUS_INVALID_PREPARSED_DATA
                // https://docs.microsoft.com/windows-hardware/drivers/ddi/hidpi/nf-hidpi-hidp_getbuttoncaps
                isGetCaps = getCapResult == NativeMethods.HIDP_STATUS.SUCCESS;
            }

            if (!isGetCaps)
            {
                throw new GetHidCapabilitiesException($"Could not get capabilities by this {nameof(handle)}: {handle}");
            }

            return(capabilities);
        }
예제 #2
0
 internal static extern HIDP_STATUS HidP_GetCaps(SafePreParsedDataHandle preparsedData, [MarshalAs(UnmanagedType.LPStruct), In, Out] HidCapabilities capabilities);