DeviceIoControl

K

Ken Allen

I am looking for information on using the [DeviceIoControl] Win32 API
procedure, or its equivalent in C#. I have looked but can find no
satisfactory references.

I am working on an existing product that has a few kernel components (device
and filter drivers) and I need to be able to communicate with these
components. I am replacing some older C++ code that used [DeviceIoControl]
to perform this communication. Also, there is some low level information,
such as drive geometry, that can be retrieved by sending
[IOCTL_DISK_GET_DRIVE_GEOMETRY] to a device object.

One reference speaks of placing the calls in unmanaged C++ code and expose
these classes to the .Net applications, but I would prefer to use all
managed code.

Another approach speaks of using PInvoke. This seems to be overly
complicated.

I did find a reference that indicated that 'sequential structure layouts'
could be used to define the structures passed into and received from the
kernel components, and that the API calls could be defined using [DllImport]
declarations. This seems more promising, but it requires that I define all
of the structures myself (they are already defined in the API), and it is
not clear how variable length structures would be handled.

Are there any simpler interfaces for communciating directly with kernel
components? Is there a ,Net replacement for [DeviceIoControl]? Is there a
better way of using this API?

-Ken
 
M

Mattias Sjögren

Ken,
One reference speaks of placing the calls in unmanaged C++ code and expose
these classes to the .Net applications, but I would prefer to use all
managed code.

Well you could use Managed C++ if you want.

Another approach speaks of using PInvoke. This seems to be overly
complicated.

I did find a reference that indicated that 'sequential structure layouts'
could be used to define the structures passed into and received from the
kernel components, and that the API calls could be defined using [DllImport]
declarations. This seems more promising

This *is* P/Invoke.

and it is not clear how variable length structures would be handled.

See if this helps

http://www.dotnetinterop.com/faq/?q=VariableLengthStruct



Mattias
 
W

Willy Denoyette [MVP]

Use the System.Management classes WMI to read driver information such as
drive geometry.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top