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 8624301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:29:37+00:00 2026-06-12T07:29:37+00:00

I am fairly new to C# as well as windows programming and I am

  • 0

I am fairly new to C# as well as windows programming and I am attempting to establish communication between a USB HID device. I got the device path successfully using ‘SetupDiGetDevicexxxxxx’ and used ‘CreateFile()’ to get Handle. Below is my code.

public const uint FILE_SHARE_READ = 0x00000001;
public const uint FILE_SHARE_WRITE = 0x00000002;
public const int OPEN_EXISTING = 3;
public const uint GENERIC_READ = 0x80000000;
public const uint GENERIC_WRITE = 0x40000000;
CreateFile(string Devicepath)
{
    HidHandle = CreateFile(Devicepath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);                     
}

After obtaining Device handle info, I am calling write file functions as below.

Result = WriteFile(HidHandle, outputReportBuffer[], outputReportBuffer.Length, NumberOfBytesWritten, 0);     

Outputbuffer is the byte array of length 8. For some reason, I was not able to write to USB HID device. “Result” is always zero. Any Help is appreciated. Also, can any one tell me how to verify that HidHandle is a valid or not. When I run the program I am getting it as “1124”.

I did followed previous post on this type of question: Cannot communicate successfully with USB HID device using writefile(), but no help.

Below are the two menthods for create file and writefile.

[DllImport("kernel32.dll", SetLastError = true)]
private static extern int CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, uint lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, uint hTemplateFile );    

[DllImport("kernel32.dll")]
static public extern bool WriteFile(int hFile,  byte lpBuffer, int nNumberOfBytesToWrite,  int lpNumberOfBytesWritten, int lpOverlapped)  
  • 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-12T07:29:38+00:00Added an answer on June 12, 2026 at 7:29 am

    You’ll probably have to use a USB library, like this one

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

Sidebar

Related Questions

I am fairly new to programming with the Play framework as well as Akka,
I'm very much new to programming and have been doing fairly well so far.
I'm fairly new to Stack Overflow as well as C programming, hope I don't
I am fairly new to Unity, (well, IoC and DI in general), and am
Fairly new to programming. I just can't wrap my head around how to get
Being fairly new to programming, I am having trouble understanding exactly what Homebrew does...
I am fairly new to Python programming, and completely new to cross-platform GUI building
Fairly new to socket programming, but I've been assigned with a whopper of project.
I am fairly new to Android development as well as Java and i am
I am fairly new to Entity framework as well as LINQ. I have used

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.