<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[James's Programming Page — WinHidDevice.ReportDescriptorReconstructor.cs NotImplException - fix]]></title>
		<link>https://swforum.seekye.com/topic/10127/</link>
		<atom:link href="https://swforum.seekye.com/feed/rss/topic/10127/" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in WinHidDevice.ReportDescriptorReconstructor.cs NotImplException - fix.]]></description>
		<lastBuildDate>Thu, 11 Jul 2019 07:25:02 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[WinHidDevice.ReportDescriptorReconstructor.cs NotImplException - fix]]></title>
			<link>https://swforum.seekye.com/post/13069/#p13069</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (martin.holden)]]></author>
			<pubDate>Thu, 11 Jul 2019 07:25:02 +0000</pubDate>
			<guid>https://swforum.seekye.com/post/13069/#p13069</guid>
		</item>
	</channel>
</rss>
