<p>Before I jump headlong into C#...</p>

<p>I've always felt that C, or maybe C++, was best for developing drivers on Windows.  I'm not keen on the idea of developing a driver on a .NET machine.</p>

<p>But .NET seems to be the way MS is heading for applications development, and so I'm now wondering:</p>

<ul>
<li>Are people are using C# to develop drivers?</li>
<li>Do you have to do a lot of API hooks, or does C# have the facilities to interface with the kernel without a lot of hackery?</li>
<li>Can anyone speak to the reliability and safety of running a C# program closer to Ring 0 than would normally be the case?</li>
</ul>

<p>I want my devices to be usable in C#, and if driver dev in C# is mature that's obviously the way to go, but I don't want to spend a lot of effort there if it's not recommended.</p>

<ul>
<li>What are some good resources to get started, say, developing a simple virtual serial port driver?</li>
</ul>

<p>-Adam</p>

[{'answer_id': 75925, 'author': 'Mladen Janković', 'author_id': 6300, 'author_profile': 'https://Stackoverflow.com/users/6300', 'pm_score': 2, 'selected': False, 'text': '<p>It\'s not direct answer to your question but if you\'re interested you might look at <a href="http://research.microsoft.com/os/Singularity/" rel="nofollow noreferrer">Singularity project</a>.</p>\n'}, {'answer_id': 75963, 'author': 'scable', 'author_id': 8942, 'author_profile': 'https://Stackoverflow.com/users/8942', 'pm_score': 2, 'selected': False, 'text': '<p>This shall help you in a way: <a href="http://www.microsoft.com/whdc/devtools/wdk/default.mspx" rel="nofollow noreferrer">Windows Driver Kit</a></p>\n'}, {'answer_id': 75974, 'author': 'Robert Gatliff', 'author_id': 9367, 'author_profile': 'https://Stackoverflow.com/users/9367', 'pm_score': 1, 'selected': False, 'text': '<p>Microsoft has a number of research projects in the area of having a managed-code OS, in other words kill with Win32 API.</p>\n\n<p>See Mary Jo Foley\'s article: <a href="http://reddevnews.com/features/article.aspx?editorialsid=2555" rel="nofollow noreferrer">Rebuilding a Legacy</a></p>\n'}, {'answer_id': 76051, 'author': 'Lasse V. Karlsen', 'author_id': 267, 'author_profile': 'https://Stackoverflow.com/users/267', 'pm_score': 6, 'selected': True, 'text': '<p>You can not make kernel-mode device drivers in C# as the runtime can\'t be safely loaded into ring0 and operate as expected.</p>\n\n<p>Additionally, C# doesn\'t create binaries suitable for loading as device drivers, particularly regarding entry points that drivers need to expose. The dependency on the runtime to jump in and analyze and JIT the binary during loading prohibits the direct access the driver subsystem needs to load the binary.</p>\n\n<p>There is work underway, however, to lift some device drivers into user mode, you can see an interview <a href="http://channel9.msdn.com/posts/Charles/Peter-Wieland-User-Mode-Driver-Framework/" rel="noreferrer">here</a> with Peter Wieland of the UDMF (User Mode Driver Framework) team.</p>\n\n<p>User-mode drivers would be much more suited for managed work, but you\'ll have to google a bit to find out if C# and .NET will be directly supported. All I know is that kernel level drivers are not doable in only C#.</p>\n\n<p>You can, however, probably make a C/C++ driver, and a C# service (or similar) and have the driver talk to the managed code, if you absolutely have to write a lot of code in C#.</p>\n'}, {'answer_id': 76091, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 2, 'selected': False, 'text': "<blockquote>\n  <p>Can anyone speak to the reliability and safety of running a C# program closer to Ring 0 than would normally be the case?</p>\n</blockquote>\n\n<p>C# runs in the .NET Virtual Machine, you can't move it any closer to Ring 0 than the VM is, and the VM runs in userspace.</p>\n"}, {'answer_id': 76308, 'author': 'Thomas Danecker', 'author_id': 9632, 'author_profile': 'https://Stackoverflow.com/users/9632', 'pm_score': 1, 'selected': False, 'text': '<p>Writing device drivers in .net makes no sense for current versions of windows.</p>\n\n<p>&lt;speculation&gt;<br>\nRumors are that MS is investing a lot of money in bringing Singularity to the next level. Just look for <a href="http://en.wikipedia.org/wiki/Midori_(operating_system)" rel="nofollow noreferrer">Midori</a>. But that\'s 2015+<br>\n&lt;/speculation&gt;</p>\n'}, {'answer_id': 1753457, 'author': 'Jeffrey Hantin', 'author_id': 55637, 'author_profile': 'https://Stackoverflow.com/users/55637', 'pm_score': 2, 'selected': False, 'text': '<p>If you\'re willing to have a go at a proprietary framework, <a href="http://www.jungo.com/st/windriver_usb_pci_driver_development_software.html" rel="nofollow noreferrer">Jungo\'s WinDriver toolkit</a> supports user-mode driver development (even in managed code) for USB, PCI, and PCI-E devices.</p>\n'}, {'answer_id': 50309676, 'author': 'unknown6656', 'author_id': 3902603, 'author_profile': 'https://Stackoverflow.com/users/3902603', 'pm_score': 1, 'selected': False, 'text': '<p>If I remember it correctly, the <a href="https://dokan-dev.github.io/" rel="nofollow noreferrer">Dokan Project</a> is a user-mode file system driver, which also allows .NET code to be executed by a system driver: <a href="https://github.com/dokan-dev/dokan-dotnet" rel="nofollow noreferrer">https://github.com/dokan-dev/dokan-dotnet</a>.</p>\n\n<p>So, you could develop a C# "driver" (user-mode application really), which is then called/invoked by a C++ kernel-mode driver. The kernel-driver could simply pass everything along without manipulating the data and act as a simple wrapper.\n<br/>\nNeedless to mention, that it is very unsafe and you would most likely end with a BSOD (I tried it).</p>\n\n<hr/>\n\n<p><em>Mildly related:</em></p>\n\n<p>The <a href="http://gocosmos.org" rel="nofollow noreferrer">Cosmos Project</a> is an open-source Operating system, which is developed in C# and runs<br/>\n"(kernel) drivers" and user-level applications written completely in C#/F#/VB.NET/...</p>\n\n<p>Though these are technically kernel-level drivers, the OS is no longer Windows but your own, so I guess that this is not a correct answer ......</p>\n'}]
['https://Stackoverflow.com/questions/75886', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2915/']