Click here to Skip to main content
15,860,943 members
Articles / Programming Languages / C#
Article

A USB HID Component for C#

Rate me:
Please Sign up or sign in to vote.
4.12/5 (86 votes)
22 Mar 2007CPOL1 min read 1.9M   68.4K   240   339
A component to communicate with a USB HID device

Introduction

This article is about a USB HID component which enables you to communicate with HID devices over USB. There is no default component available for USB at this moment, and this component should provide you with a good starting point when writing your own USB HID enabled applications.

This article provides a sample application as well as the component itself.

Background

The component is based on various sources. A good start for USB in C# is this website. Also the book USB COMPLETE (third edition) by Jan Axelson is a must read for anyone wishing to incorporate USB HID into her/his application.

The component is developed during a project at the Avans Hogeschool in 's-Hertogenbosch, The Netherlands.

Using the Code

In the provided sample application, there is a good demonstration on how to include the component. Moreover, the use of the component is very well demonstrated. The only thing that must be done in your own application is implementing the events.

You'll also have to override the following functions in your form, so that your program is USB aware. In the property box, you'll have to provide a vendor and product id of your USB device in order to detect the correct device.

C#
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
usb.RegisterHandle(Handle);
}
protected override void WndProc(ref Messagea m)
{
usb.ParseMessages(ref m);
base.WndProc(ref m); // pass message on to base form
}

Points of Interest

A mouse is always in use by Windows, and cannot be captured by your own application. This also applies to HID devices in use by other applications.

History

  • 22nd March, 2007: First version, currently in development

Updates will be posted if there is a need for them.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionCross Platform USB/Hid Component Pin
TheChristian15-Jan-19 19:54
TheChristian15-Jan-19 19:54 
Questiongood job,and i have some question Pin
jamesauos21-Aug-18 4:50
jamesauos21-Aug-18 4:50 
GeneralRe: good job,and i have some question Pin
jamesauos22-Aug-18 7:01
jamesauos22-Aug-18 7:01 
QuestionHID over WiFi Pin
Mehrdad_K20-Aug-18 21:55
professionalMehrdad_K20-Aug-18 21:55 
Question64bit gets wrong GUID, and bytes not copied? Pin
Member 126652188-Jul-17 16:54
Member 126652188-Jul-17 16:54 
QuestionProject_for win 8 64 Pin
Andrew Vatoropin2-Dec-16 3:13
Andrew Vatoropin2-Dec-16 3:13 
QuestionNow working Pin
Andrew Vatoropin1-Dec-16 19:29
Andrew Vatoropin1-Dec-16 19:29 
AnswerRe: Now working Pin
Andrew Vatoropin1-Dec-16 19:43
Andrew Vatoropin1-Dec-16 19:43 
GeneralThis project is very good! Pin
Efforts23-Oct-16 17:36
Efforts23-Oct-16 17:36 
Questionwhen i enter VID and PID i get nothing ... can any one help me? Pin
Member 1216412614-Oct-16 4:32
Member 1216412614-Oct-16 4:32 
AnswerRe: when i enter VID and PID i get nothing ... can any one help me? Pin
Member 126652188-Jul-17 16:55
Member 126652188-Jul-17 16:55 
QuestionHow to test the Sniffer tools Pin
Member 1200259722-Sep-15 17:45
Member 1200259722-Sep-15 17:45 
Question.dll' doesn't contain any UserControl types. Pin
Member 1185447122-Jul-15 2:44
Member 1185447122-Jul-15 2:44 
AnswerRe: .dll' doesn't contain any UserControl types. Pin
Enisor Marius27-Aug-15 1:49
Enisor Marius27-Aug-15 1:49 
AnswerRe: .dll' doesn't contain any UserControl types. Pin
Andrew Vatoropin1-Dec-16 19:33
Andrew Vatoropin1-Dec-16 19:33 
QuestionHow can it detect a HID device while working in a Remote Desktop (by mstsc) Pin
Member 1167099913-May-15 2:57
Member 1167099913-May-15 2:57 
QuestionReading from USB device Pin
Dredd7513-Feb-15 12:03
Dredd7513-Feb-15 12:03 
AnswerRe: Reading from USB device Pin
Dredd7514-Feb-15 12:12
Dredd7514-Feb-15 12:12 
GeneralRe: Reading from USB device Pin
shailesh_sharma7868-Jul-15 19:53
shailesh_sharma7868-Jul-15 19:53 
GeneralRe: Reading from USB device Pin
amigoface16-Oct-16 6:19
amigoface16-Oct-16 6:19 
QuestionSpecifiedDevice Pin
jeremystein123414-Jan-15 10:27
jeremystein123414-Jan-15 10:27 
AnswerRe: SpecifiedDevice Pin
Member 1478500418-Apr-20 11:23
Member 1478500418-Apr-20 11:23 
QuestionHow to write data in USB HID device? Pin
Member 112767143-Dec-14 19:46
Member 112767143-Dec-14 19:46 
QuestionHow to support more than one device with similar PID and VID and different serial Pin
elekgeek1-Dec-14 20:36
elekgeek1-Dec-14 20:36 
QuestionSerial Number of HID device Pin
elekgeek30-Nov-14 0:03
elekgeek30-Nov-14 0:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.