Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9224309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:17:16+00:00 2026-06-18T04:17:16+00:00

I’m developing a USB device as a standard HID keyboard with an 8-byte feature

  • 0

I’m developing a USB device as a standard HID keyboard with an 8-byte feature report added to the report descriptor; I’m writing an host app to configure the device. I’m trying to adapt the wonderful HidLibrary to utilize the HidD_GetFeature() function in hid.dll.

Before I start posting c# code, I will say that I have successfully tested my firmware using the SimpleHidWrite utility with both Get and Set Feature commands, so I’m fairly confident that’s not the issue.

The HidD_SetFeature() function, as wrapped in the HidLibrary API, works great. I can write 8 bytes to the device and I’ve verified using the SimpleHidWrite tool that they are stored correctly. However, I can’t pull those bytes back using HidD_GetFeature(), and I’m baffled as to why.

Here are what I believe to be the pertinent details.

First, the CreateFile call built into the library with values:

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    internal static IntPtr CreateFile(
        string lpFileName,
        uint dwDesiredAccess,
        int dwShareMode,
        ref HidLibrary.NativeMethods.SECURITY_ATTRIBUTES lpSecurityAttributes,
        int dwCreationDisposition,
        int dwFlagsAndAttributes,
        int hTemplateFile);

where (using test vid/pid):

lpFileName = "\\?\hid#vid_03eb&pid_2042#7&1fef463f&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"
dwDesiredAccess = 0
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE (0x01 | 0x02)
lpSecurityAttributes = { bInheritHandle = true, lpSecurityDescriptor = 0, nLength = 12 }
dwCreationDisposition = OPEN_EXISTING (3)
dwFlagsAndAttributes = 0
hTemplateFile = 0

The import definition:

[DllImport("hid.dll", SetLastError = true)]
    static internal extern bool HidD_GetFeature(IntPtr hidDeviceObject, ref byte[] lpReportBuffer, int reportBufferLength);

And finally the API method I’m creating that is currently failing on the HidD_GetFeature() call with error 23 (ERROR_CRC):

    public bool ReadFeatureData(byte reportId, out byte[] data)
    {
        if (_deviceCapabilities.FeatureReportByteLength <= 0)
        {
            data = new byte[0];
            return false;
        }
        // FeatureReportByteLength returns 9 (byte 0 is the report id and 8 bytes for the actual report length)
        data = new byte[_deviceCapabilities.FeatureReportByteLength];

        //yields a 9-byte array
        var buffer = this.CreateFeatureInputBuffer(); 
        buffer[0] = reportId;

        IntPtr hidHandle = IntPtr.Zero;
        bool success = false;
        try
        {
            // Performs the CreateFile call above resulting in an IntPtr handle
            hidHandle = OpenDeviceIO(_devicePath, NativeMethods.ACCESS_NONE);

            success = NativeMethods.HidD_GetFeature(hidHandle, ref buffer, buffer.Length);
            // at this point, success is false, and buffer has gone from 9 bytes to 1

            if(success)
            {
                Array.Copy(buffer, 0, data, 0, Math.Min(data.Length, _deviceCapabilities.FeatureReportByteLength));
            }
            else
            {
                //Yes, i know casting to a byte isn't good here; it's dirty but helping me debug for now
                data[0] = (byte)Marshal.GetLastWin32Error(); //returns 23 (verified, actual) - ERROR_CRC
            }

        }
        catch (Exception exception)
        {
            throw new Exception(string.Format("Error accessing HID device '{0}'.", _devicePath), exception);
        }
        finally
        {
            if (hidHandle != IntPtr.Zero)
                CloseDeviceIO(hidHandle);
        }

        return success;
    }

I’ve read there are some issues with working with system devices like keyboards and mice, and that may or may not play in here, however I know that it’s possible to interact with the device in the way I’m trying because I was able to do so with SimpleHidWrite. That said, I haven’t ruled anything out and any ideas are welcome.

Let me know if I need to provide any more info.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:17:17+00:00Added an answer on June 18, 2026 at 4:17 am

    I think this declaration may be the problem.

    [DllImport("hid.dll", SetLastError = true)]
        static internal extern bool HidD_GetFeature(IntPtr hidDeviceObject, ref byte[] lpReportBuffer, int reportBufferLength);
    

    Try changing the lpReportBuffer ref parameter to out, or omitting it altogether.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an app with both english and french support. The app requests
I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am using Paperclip to handle profile photo uploads in my app. They upload
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.