By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,198 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,198 IT Pros & Developers. It's quick & easy.

Can we Write a device Driver using CSharp

P: n/a
Hi All,

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

Thanks,
Ritu
Nov 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.