473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Can we Write a device Driver using CSharp

Hi All,

Can any body please tell me how i can write a device driver using CSharp.

Thanks,
Ritu
Nov 17 '05 #1
7 4395
You can't write device drivers in managed code, therefore you can't write a
device driver in C#.

You'll need to write it in either assembly or unmanaged C/C++.

Pete

"Ritu" <ri***@momentum-tech.com> wrote in message
news:uv*************@TK2MSFTNGP12.phx.gbl...
Hi All,

Can any body please tell me how i can write a device driver using CSharp.

Thanks,
Ritu

Nov 17 '05 #2
In short... no.

Why? In long... Applications and libraries built with C# require the .NET
Framework and the Common Language Runtime (CLR) in order to operate... both
of which operate in user mode, device drivers on the other hand operate in
kernel mode.

If that wasn’t enough, even if it was possible today to have CLR code run in
kernel mode, the basic overhead of the CLR (garbage collection, reference and
type checking, etc) would be likely to cause undesirable system slowdowns.

I have heard of some work being done at Microsoft to make it possible to
write user mode device drivers, especially useful for low bandwidth and high
latency devices that do not need the benefits of kernel mode. In theory, if
such an ability ends up in shipping products, it would be possible to write a
driver in C#... until then, we are stuck with more low level languages like C
and C++.

Brendan
"Ritu" wrote:
Hi All,

Can any body please tell me how i can write a device driver using CSharp.

Thanks,
Ritu

Nov 17 '05 #3
Pete,

While you can not write device drivers directly in .NET, that doesn't
mean you can't use them.

C# does not have the ability to export functions from DLLs. This is the
reason you can not write device drivers with C#.

That doesn't stop you from creating an unmanaged dll and then calling
..NET code from within that. However, for device drivers, this is something
you definitely don't want to do.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message
news:1u********************@giganews.com...
You can't write device drivers in managed code, therefore you can't write
a device driver in C#.

You'll need to write it in either assembly or unmanaged C/C++.

Pete

"Ritu" <ri***@momentum-tech.com> wrote in message
news:uv*************@TK2MSFTNGP12.phx.gbl...
Hi All,

Can any body please tell me how i can write a device driver using CSharp.

Thanks,
Ritu


Nov 17 '05 #4
Inline

Willy.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eK**************@TK2MSFTNGP09.phx.gbl...
Pete,

While you can not write device drivers directly in .NET, that doesn't
mean you can't use them.

C# does not have the ability to export functions from DLLs. This is
the reason you can not write device drivers with C#.

This is not the only reason though, the only kernel mode driver development
environment supported by MSFT is the driver development kit, it uses it's
own set of tools like C++ compiler and linker (the latest version 13.10) and
it's own set of libraries (not necessarily the same as the VS or sdk libs.).
You can't use template classes and the C++ template libraries, great care
must be taken when using the standard C library when doing kernel mode
development, some functions should not be called at all, so you should not
use frameworks build in top of the C++ and C runtime libary (like the CLR).
You should not introduce the COM library (ole32.dll) into kernel mode driver
(like the CLR does) nor should you use other high level C++ based frameworks
like ATL and MFC.
Another restriction is that device drivers must use structured exception
handling and NOT something built on top of it like C++ exceptions (like the
C++ template lib.) and CLR exceptions. And don't forget, device drivers
cannot stand asynchronous exceptions ;-).
And last but not least they have very restrictive memory constraints, you
can't run device drivers that allocate 32 MB heap (in kernel space) space
for the GC heap, he you can't (or shouldn't) even use malloc or new.
So you see, this is not the place to be for managed code.
That doesn't stop you from creating an unmanaged dll and then calling
.NET code from within that. However, for device drivers, this is
something you definitely don't want to do.

And what would be the purpose of this unmanaged DLL?
C# applications can directly call into device drivers IOCTL interface
through PInvoke.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message
news:1u********************@giganews.com...
You can't write device drivers in managed code, therefore you can't write
a device driver in C#.

You'll need to write it in either assembly or unmanaged C/C++.

Pete

"Ritu" <ri***@momentum-tech.com> wrote in message
news:uv*************@TK2MSFTNGP12.phx.gbl...
Hi All,

Can any body please tell me how i can write a device driver using
CSharp.

Thanks,
Ritu



Nov 17 '05 #5
Thanks a Lot for your answers
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:u8**************@TK2MSFTNGP15.phx.gbl...
Inline

Willy.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:eK**************@TK2MSFTNGP09.phx.gbl...
Pete,

While you can not write device drivers directly in .NET, that doesn't
mean you can't use them.

C# does not have the ability to export functions from DLLs. This is
the reason you can not write device drivers with C#.

This is not the only reason though, the only kernel mode driver

development environment supported by MSFT is the driver development kit, it uses it's
own set of tools like C++ compiler and linker (the latest version 13.10) and it's own set of libraries (not necessarily the same as the VS or sdk libs.). You can't use template classes and the C++ template libraries, great care
must be taken when using the standard C library when doing kernel mode
development, some functions should not be called at all, so you should not
use frameworks build in top of the C++ and C runtime libary (like the CLR). You should not introduce the COM library (ole32.dll) into kernel mode driver (like the CLR does) nor should you use other high level C++ based frameworks like ATL and MFC.
Another restriction is that device drivers must use structured exception
handling and NOT something built on top of it like C++ exceptions (like the C++ template lib.) and CLR exceptions. And don't forget, device drivers
cannot stand asynchronous exceptions ;-).
And last but not least they have very restrictive memory constraints, you
can't run device drivers that allocate 32 MB heap (in kernel space) space
for the GC heap, he you can't (or shouldn't) even use malloc or new.
So you see, this is not the place to be for managed code.
That doesn't stop you from creating an unmanaged dll and then calling
.NET code from within that. However, for device drivers, this is
something you definitely don't want to do.


And what would be the purpose of this unmanaged DLL?
C# applications can directly call into device drivers IOCTL interface
through PInvoke.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message
news:1u********************@giganews.com...
You can't write device drivers in managed code, therefore you can't write a device driver in C#.

You'll need to write it in either assembly or unmanaged C/C++.

Pete

"Ritu" <ri***@momentum-tech.com> wrote in message
news:uv*************@TK2MSFTNGP12.phx.gbl...
Hi All,

Can any body please tell me how i can write a device driver using
CSharp.

Thanks,
Ritu



Nov 17 '05 #6
If i cannot expose Funtions form DLl, How i can support an API Interface.

I need to write a DLL which should be able to expose some functions as well
as GUI screens. Any client
should be able to use the GUI and the functions exposed by the DLL.

Please suggest How should i go about it Using C#.

Thanks in Advance,
Ritu


"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eK**************@TK2MSFTNGP09.phx.gbl...
Pete,

While you can not write device drivers directly in .NET, that doesn't
mean you can't use them.

C# does not have the ability to export functions from DLLs. This is the reason you can not write device drivers with C#.

That doesn't stop you from creating an unmanaged dll and then calling
.NET code from within that. However, for device drivers, this is something you definitely don't want to do.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message
news:1u********************@giganews.com...
You can't write device drivers in managed code, therefore you can't write a device driver in C#.

You'll need to write it in either assembly or unmanaged C/C++.

Pete

"Ritu" <ri***@momentum-tech.com> wrote in message
news:uv*************@TK2MSFTNGP12.phx.gbl...
Hi All,

Can any body please tell me how i can write a device driver using CSharp.
Thanks,
Ritu



Nov 17 '05 #7
You can export functionality in C# DLLs, you just can't expose them to
direct calls from unmanaged code. I think that's where Nicholas was going.

On the other hand, you can reference DLLs written in C# by other .NET
languages, in which case they just natively use the classes contained in the
DLLs. You simply have to add the DLL as a reference.

If you need to access your C# DLLs from unmanaged code, you can export your
C# classes as COM objects and then you can access them just like other COM
objects from unmanaged code.

This is all completely separate from device drivers, though, which don't
support any of this stuff.

In fact, most large .NET apps tend to be composed of an executeable and one
or more .NET .DLLs that all work together. And then the entire .NET
framework itself is simply a collection of DLLs which you reference from
your C# app.

Pete

"Ritu" <ri***@momentum-tech.com> wrote in message
news:OI**************@TK2MSFTNGP10.phx.gbl...
If i cannot expose Funtions form DLl, How i can support an API Interface.

I need to write a DLL which should be able to expose some functions as
well
as GUI screens. Any client
should be able to use the GUI and the functions exposed by the DLL.

Please suggest How should i go about it Using C#.

Thanks in Advance,
Ritu


"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:eK**************@TK2MSFTNGP09.phx.gbl...
Pete,

While you can not write device drivers directly in .NET, that doesn't
mean you can't use them.

C# does not have the ability to export functions from DLLs. This is

the
reason you can not write device drivers with C#.

That doesn't stop you from creating an unmanaged dll and then calling
.NET code from within that. However, for device drivers, this is

something
you definitely don't want to do.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message
news:1u********************@giganews.com...
> You can't write device drivers in managed code, therefore you can't write > a device driver in C#.
>
> You'll need to write it in either assembly or unmanaged C/C++.
>
> Pete
>
> "Ritu" <ri***@momentum-tech.com> wrote in message
> news:uv*************@TK2MSFTNGP12.phx.gbl...
>> Hi All,
>>
>> Can any body please tell me how i can write a device driver using CSharp. >>
>> Thanks,
>> Ritu
>>
>>
>
>



Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Wouter van Ooijen | last post by:
I want to use Python to interface with an USB HID device (not a keyboard or mouse, just something that uses the HID driver to avoid the need for a specific driver). Is this possible in pure Python...
2
by: nbhalala | last post by:
Hello Friends, Hi Myself Naresh (B.E. Comp. Eng) from Mumbai... I'm a Linux Device Driver Writer... I would like to learn writing Driver of "USB Devices"...BUT before that I'm presently working...
12
by: Steve | last post by:
I wrote a simple virtual device driver int15.sys, Is C# support load the device driver from AP?
8
by: Tony Liu | last post by:
I am having a "Null Device is Missing" compile error when compiling a c++ project. The documentation from MSDN said it could be caused by low system resource or the user account does not have...
3
by: bb | last post by:
I have a windows network device driver written in c++ and a user interface im porting to c#, my problem is i dont seem to be getting notified of the event calls from the driver to the c# app im...
5
by: Tom | last post by:
I am converting an old application that was printing directly to a specialized printer device (i.e. a special label printer). It was doing this by opening a file with the file path of 'LPT1:' and...
4
by: Thomi Aurel RUAG A | last post by:
Hy Mike Thanks for your links, unfortunately they weren't very usefull for my specific problem. Hy Grant Edwards Thanks for your hints. A simplified test programm to compare the function for...
0
by: Shival | last post by:
Hi, I have a Device that will be used by dentist to take their paitient teaath pics. this Device is having a click button from which the device takes pics. The Device is configured to my OS...
1
by: =?Utf-8?B?15DXldeo158=?= | last post by:
I have recently installed my windows XP, the process went smoothly, but I had encounterd some drivers issues after the installation. I managed to solve the ethernet adapter driver issue, but I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.