Writing drivers in C#

拈花ヽ惹草 提交于 2019-11-27 01:16:07

问题


I have written earlier in C/C++ but currently, I need it to convert into C#.

Can anyone tell me the code/way How to write drivers in C#?

Actually currently I have some problems with my old application written in C++ and we have to write the drivers of our LPT1,COM Printers and other USB drivers in C#.


回答1:


Simply you can't. C# produces intermediate language that is interpreted by a virtual machine (.NET). All these stuff runs in user mode and WDM drivers run in kernel mode.

There is a DDK but it is not supported in VStudio either (but you can make a makefile project for compilation though).

Driver development is complex, prone to blue screen and requires a good understanding of C , kernel structures and mem manipulation. None of those skills are required for C# and .NET therefore there is a long and painful training path.




回答2:


Actually, you can write some drivers in C# if you use UMDF because it runs in usermode (see Getting Started with UMDF). But my recommendation is to use C/C++.




回答3:


You cannot write kernel mode drivers in C# (the runtime executes in user mode therefore you can't get into ring0). This SO Q/A provides some links you may find helpful:

C# driver development?




回答4:


It's unclear from your description whether you intend to develop Windows device drivers or to interact with hardware through existing device drivers.

For example, to interact with devices connected to your serial port, you don't need to write your own driver and in fact, you can access it through .NET's SerialPort class.

Even USB devices can be accessed from user space (and, ultimately, managed code) through frameworks such as libusb-win32, WinUSB etc.




回答5:


You can't write drivers in C#; drivers need to run with elevated privilege to be able to talk to hardware; managed code cannot be run in the appropriate environment.



来源:https://stackoverflow.com/questions/994600/writing-drivers-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!