<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[James's Programming Page — WinHidDevice.ReportDescriptorReconstructor.cs NotImplException - fix]]></title>
	<link rel="self" href="https://swforum.seekye.com/feed/atom/topic/10127/" />
	<updated>2019-07-11T07:25:02Z</updated>
	<generator>PunBB</generator>
	<id>https://swforum.seekye.com/topic/10127/</id>
		<entry>
			<title type="html"><![CDATA[WinHidDevice.ReportDescriptorReconstructor.cs NotImplException - fix]]></title>
			<link rel="alternate" href="https://swforum.seekye.com/post/13069/#p13069" />
			<content type="html"><![CDATA[<p>We have a number of devices that are throwing a NotImplementedException() in WinHidDevice.ReportDescriptorReconstructor.cs@171 [v2.1.0] during open. I propose the following code to mitigate the problem. Whether this fixes for all cases I cannot be sure but it seems to for us. I guess it shouldn&#039;t be a big deal if no-one else has previously reported this. </p><p>Thank you for your efforts.</p><br /><div class="codebox"><pre><code>else if (dataIndexCount == 1)
                        {
                            // Array...
                            int bitCount = reportItem.ReportCount * reportItem.ReportSize;
                            var usageValue = new byte[(bitCount + 7) / 8];
                            for (int i = 0; i &lt; usageValue.Length; i++) { usageValue[i] = 0xff; }
                            int hr = NativeMethods.HidP_SetUsageValueArray(reportType, item.UsagePage, item.LinkCollection, item.UsageIndex, usageValue, (ushort)usageValue.Length, _preparsed, reportBytes, reportBytes.Length);
                            if (hr == NativeMethods.HIDP_STATUS_SUCCESS)
                            {
                                GetDataStartBit(reportBytes, reportItem, maxBit);
                            }
                            else if (hr == NativeMethods.HIDP_STATUS_NOT_VALUE_ARRAY) // +++[
                            {                                
                                hr = NativeMethods.HidP_SetUsageValue(reportType, item.UsagePage, item.LinkCollection, item.UsageIndex, 0xffffffff, _preparsed, reportBytes, reportBytes.Length);
                                if (hr == NativeMethods.HIDP_STATUS_SUCCESS)
                                {
                                    GetDataStartBit(reportBytes, reportItem, maxBit);
                                }
                                else // ]+++
                                {
                                    throw new NotImplementedException();
                                }
                            }
                        }
                        else
                        ...</code></pre></div><p>You&#039;ll need to add the following two items to NativeMethods.cs as well:<br /></p><div class="codebox"><pre><code>public static readonly int HIDP_STATUS_NOT_VALUE_ARRAY = HIDP_ERROR_CODES(12, 11);

[DllImport(&quot;hid.dll&quot;, CharSet = CharSet.Auto)]
        public unsafe static extern int HidP_SetUsageValue(HIDP_REPORT_TYPE reportType, ushort usagePage, ushort linkCollection, ushort usage, uint usageValue, IntPtr preparsed, byte[] report, int reportLength);</code></pre></div>]]></content>
			<author>
				<name><![CDATA[martin.holden]]></name>
				<uri>https://swforum.seekye.com/user/14295/</uri>
			</author>
			<updated>2019-07-11T07:25:02Z</updated>
			<id>https://swforum.seekye.com/post/13069/#p13069</id>
		</entry>
</feed>
