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

Help with DeviceIoControl PInvoke

P: n/a
Helo,

I'm having problems here with the input buffer.... Ive defined the API call
as:

<System.Runtime.InteropServices.DllImport("kernel3 2", SetLastError:=True)> _
Private Shared Function DeviceIoControl(ByVal hDevice As IntPtr, ByVal
dwIoControlCode As Integer, ByVal lpInBuffer As IntPtr, ByVal nInBuffer As
Integer, ByRef lpOutBuffer As IntPtr, ByVal nOutBufferSize As Integer, ByRef
lbBytesResturned As Integer, ByVal lpOverlapped As IntPtr) As Boolean
End Function

<System.Runtime.InteropServices.DllImport("kernel3 2", SetLastError:=True)> _
Private Shared Function DeviceIoControl(ByVal hDevice As IntPtr, ByVal
dwIoControlCode As Integer, ByVal lpInBuffer As IntPtr, ByVal nInBuffer As
Integer, ByRef lpOutBuffer As Object, ByVal nOutBufferSize As Integer, ByRef
lbBytesResturned As Integer, ByVal lpOverlapped As IntPtr) As Boolean
End Function

Al right, use CreateFile to get a handle to my device, I issue

DeviceIoControl(Me.m_Handle, IOCTL_NDISUIO_BIND_WAIT, IntPtr.Zero, 0,
IntPtr.Zero, 0, nBytesReturned, IntPtr.Zero)

wich works fine, but when I can't figure how to query the device. For
example:

DeviceIoControl(Me.m_Handle, IOCTL_NDISUIO_QUERY_BINDING, p,
System.Runtime.Interop.Marshal.sizeof(p), oBuffer, Me.m_Buffer.Length,
dwBytesWritten, IntPtr.Zero)

(Where p is a structure). This fails all the time at, it seems to throw an
exception at System.Runtime.Interop.Marshal.sizeof(p), .

This code also exists in C# where the code is:

fixed (byte* buf = Buffer)
{
...
NDISUIO_QUERY_BINDING* p = (NDISUIO_QUERY_BINDING*)buf;
...
DeviceIoControl(DriverHandle, IOCTL_NDISUIO_QUERY_BINDING, new
IntPtr(p), sizeof(NDISUIO_QUERY_BINDING), new IntPtr(buf), Buffer.Length,
out dwBytesWritten, IntPtr.Zero)
...
}

I cann't manage to port this code to VB .NET and would be pleased to receive
some help on this issue. I'm having problems to get around those pointers...

Thanyou in advance,

Juan Pedro Gonzalez
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hello Juan,

You may try to include an overloaded declare of API subroutine with
lpInBuffer and lpOutBuffer declared as NDISUIO_QUERY_BINDING, e.g:

~
Private Declare Function DeviceIoControl Lib "kernel32.dll" ( _
ByVal hDevice As IntPtr, _
ByVal dwIoControlCode As Integer, _
ByRef lpInBuffer As NDISUIO_QUERY_BINDING, _
ByVal nInBufferSize As Integer, _
ByRef lpOutBuffer As NDISUIO_QUERY_BINDING, _
ByVal nOutBufferSize As Integer, _
ByRef lpBytesReturned As Integer, _
ByVal lpOverlapped As IntPtr _
) As Boolean
~

and pass your structure into this method directly.
If this doesn't help please provide complete C# code.

Roman

"Juan Pedro Gonzalez @ .com>" <<nospamnospam> сообщил/сообщила в
новостях следующее: news:eX**************@TK2MSFTNGP11.phx.gbl...
Helo,

I'm having problems here with the input buffer.... Ive defined the API call as:

<System.Runtime.InteropServices.DllImport("kernel3 2", SetLastError:=True)> _ Private Shared Function DeviceIoControl(ByVal hDevice As IntPtr, ByVal
dwIoControlCode As Integer, ByVal lpInBuffer As IntPtr, ByVal nInBuffer As Integer, ByRef lpOutBuffer As IntPtr, ByVal nOutBufferSize As Integer, ByRef lbBytesResturned As Integer, ByVal lpOverlapped As IntPtr) As Boolean
End Function

<System.Runtime.InteropServices.DllImport("kernel3 2", SetLastError:=True)> _ Private Shared Function DeviceIoControl(ByVal hDevice As IntPtr, ByVal
dwIoControlCode As Integer, ByVal lpInBuffer As IntPtr, ByVal nInBuffer As Integer, ByRef lpOutBuffer As Object, ByVal nOutBufferSize As Integer, ByRef lbBytesResturned As Integer, ByVal lpOverlapped As IntPtr) As Boolean
End Function

Al right, use CreateFile to get a handle to my device, I issue

DeviceIoControl(Me.m_Handle, IOCTL_NDISUIO_BIND_WAIT, IntPtr.Zero, 0,
IntPtr.Zero, 0, nBytesReturned, IntPtr.Zero)

wich works fine, but when I can't figure how to query the device. For example:

DeviceIoControl(Me.m_Handle, IOCTL_NDISUIO_QUERY_BINDING, p,
System.Runtime.Interop.Marshal.sizeof(p), oBuffer, Me.m_Buffer.Length,
dwBytesWritten, IntPtr.Zero)

(Where p is a structure). This fails all the time at, it seems to throw an exception at System.Runtime.Interop.Marshal.sizeof(p), .

This code also exists in C# where the code is:

fixed (byte* buf = Buffer)
{
...
NDISUIO_QUERY_BINDING* p = (NDISUIO_QUERY_BINDING*)buf;
...
DeviceIoControl(DriverHandle, IOCTL_NDISUIO_QUERY_BINDING, new
IntPtr(p), sizeof(NDISUIO_QUERY_BINDING), new IntPtr(buf), Buffer.Length, out dwBytesWritten, IntPtr.Zero)
...
}

I cann't manage to port this code to VB .NET and would be pleased to receive some help on this issue. I'm having problems to get around those pointers...
Thanyou in advance,

Juan Pedro Gonzalez

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.