Library tutorials & articles

DeviceIoControl & USB using Managed C++ & C#

Introduction

Low level I/O is not part of the .NET framework, so information on how its done is difficult to find.  Since I am using some specialized hardware, which won't be available to most C# developers, my comments will focus on interoperability with unmanaged code.  If you happen to have the Cypress EZ-USB FX development board, you can use the code given here as a starting point.  Otherwise you can use it as a source of ideas.

Find the code at my website.

This code is my early attempt to produce a wrapper to allow .NET applications to use the device driver that comes with the Cypress development board, and is far from being complete.  As it turns out I may never complete this project.  I have purchased DriverX USB from Tetradyne.  The data acquisition system that I am working on uses a custom ISA card.  Originally I started with MSDOS, then moved to Win 95.  With MSDOS & Win 95, I could just use in & out instructions to talk directly to the hardware.  When I moved to NT 4, I purchased DriverX, which eliminated the need to write a device driver for communicating with the ISA card.  Now the data acquisition system is running on Win 2000 and XP.  The problem is that as we deploy more sites, it is getting difficult to purchase systems with ISA slots.  To eliminate the dependency on the ISA card we are moving to USB.  In the electronics crate for the data acquisition system a Cypress EZ-USB FX chip will be used.

If you want me to post articles about using DriverX, DriverX USB, and wrapping my legacy C++ code using managed C++, send me a message at wburris@telusplanet.net. My .NET reference books for this project are:

Comments

  1. 16 Aug 2006 at 07:42
     
    I want to build an application to Set/Get USB requests using the OS drivers, Can I do that ? How can I send request to USB for example : Set_Feature ?
     
    Best Regards.
    Joe
  2. 15 Sep 2005 at 14:24

    Hei!


    You can not use IJW if you are programming with C#. You can use P/Invoke where you import unmanaged dll or to make a managed wrapper class in c++ and then write a class in C# to use unmanaged class.
    You can only use IJW if you want to use unmanaged C++ class in you managed C++ class, but not in other .NET languages.

  3. 23 Nov 2004 at 07:01

    Be advised that there are bugs in this C++.


    Firstly, there is a line of code that reads


    (long *) &nBytes,


    where nBytes is declared as an int. This will lead to a stack corruption whenever sizeof(int) != sizeof(long).


    Secondly, buffers are allocated with new char [] but then are deleted with delete, not delete[]. This can lead to memory leaks.


    Thank goodness for C#!


  4. 04 Nov 2004 at 13:13

    hello,


    i am trying to wrap an unmanaged C++ code to managed one so that i can use it within c#, and i am using IJW - "It Just Works" - method for that. In the code, there is a function which takes a "filename" as one of its arguments and the type of that is "char". In the documents of msdn, "char" is mapped to String[in] or StringBuilder[in,out] by marshaller. although i searched in the goggle, i couldnt find any kinds of simple-because I am not an experienced enough- sample code that uses IJW method. I found always the ones which uses PInvoke method.


    Can you help me with marshalling "char*" type with IJW method by a simple sample code?


    Thanks!

  5. 01 Jan 1999 at 00:00

    This thread is for discussions of DeviceIoControl & USB using Managed C++ & C#.

Leave a comment

Sign in or Join us (it's free).

Bill Burris

Want to stay in touch with what's going on? Follow us on twitter!