how to write a "driver" in c#?
-
Monday, April 07, 2008 5:20 AMhi guys,i need to know can we write a "driver" for a spefic device via c#?please explain.thanks
All Replies
-
Monday, April 07, 2008 8:23 PMModerator
"drivers" in Windows are binaries with specific entry points that are called directly by the OS. Managed languages cannot contain application-developer-defined entry points and therefore you cannot write drivers in C#. -
Monday, April 07, 2008 8:29 PM
Dude, it's impossible.
-
Monday, April 07, 2008 9:28 PM
You will need Windows Driver Development Kit in order to write drivers. You can write them in c++ but not in c#. However, there are at least two operating systems written in c# so one day we might have drivers written in c#. -
Monday, April 07, 2008 10:39 PMPeter is right, you can't make a managed code program that would be able to behave properly (be accessable at the required entry points) to be a driver. This is basically the same reason you'd never see any drivers written in Java.
However, since you state it as "driver" maybe you don't need something that can help the OS understand what to do with a device.
Can you explain better what you are doing? Are you trying to communicate with a device (that already has or doesn't need it's own driver)? Depending on the device it might already use the drivers that exist, like the HID drivers or even drivers for the chipset used in the device (like devices with the FTDI USB interface chips). In those cases you only need to write a wrapper/handler to those driver's APIs for the specific device and not an actual "driver". -
Monday, April 07, 2008 10:53 PMYou probably wouldn't want to write a driver in c#, even if you could give it accessible entry points for the OS, because it would be relatively slow.
-
Monday, April 07, 2008 10:55 PMP.S. Peter Ritchie amazes me.
-
Tuesday, April 08, 2008 8:00 AMwhat do you mean by entry points in what you wrote:"drivers" in Windows are binaries with specific entry points that are called directly by the OS. Managed languages cannot contain application-developer-defined entry points and therefore you cannot write drivers in C#..By the way Thanks for your answer
-
Tuesday, April 08, 2008 1:59 PMModerator
The way the Windows loader works with binaries it that it loads the binary into memory, performs any relocations (memory references that aren't relative) and begins execution at a specific point in those instructions. That's the main entry point--whose location is defined in the binary's header. With DLLs you can have other entry points (functions) that any application can simply jump to. Those function entry points are simply offsets into the binaries instructions.
Managed compilers currently don't support these types of entry points (they don't create them) partly because these methods are simply jumped to by any code (native or managed) and the code and those entry points would have to detect if the managed runtime is running and start if not before running the application-defined code.
-
Wednesday, April 09, 2008 4:23 AMwhat are binaries any way?
-
Wednesday, April 09, 2008 3:00 PMModeratorBinaries are files that contain compiled code.

