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:
- .NET Framework Solutions: In Search of the Lost Win32 API by John Paul Mueller
- Essential Guide to Managed Extensions for C++ by Siva Challa, Artur Laksberg
Related articles
Related discussion
-
job vacancy .Net Programmers - ( C# || C++ ) (5 full-time positions)
by tajulz (0 replies)
-
How to store C++ object pointers in Core foundation's ordered collections like CFMutableArrayRef, CFMutableDictionaryRef.
by elizas (0 replies)
-
Binary Studio | software development outsourcing Ukraine
by Soft Industry (5 replies)
-
searhing numeric data in urdu text file.
by adilsajjad (0 replies)
-
Programming MS Visual C++, David J. Kruglinski - missing files needed
by andwan0 (0 replies)
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.
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#!
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!
This thread is for discussions of DeviceIoControl & USB using Managed C++ & C#.