473,378 Members | 1,152 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,378 software developers and data experts.

Help with DeviceIoControl PInvoke

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
1 4533
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jim Hubbard | last post by:
I have some C# code that is supposed to wrap the defrag APIs and I am trying to convert it to VB.Net (2003). But, I keep having problems. The C# code is relatively short, so I'll post it...
0
by: ewoo | last post by:
I'm trying to write a wrapper in csharp to wrap DeviceIoControl() win32 method for IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS control code--without much luck. I've seen lots of examples out there for...
0
by: besaar | last post by:
i got the current project that got the serial no.of a hard disk for software protection but i got an error,if u solve it send me,thanx alllllll. 1.file1 Option Strict On Option Explicit On...
2
by: Jules Crown | last post by:
Everyone, greetings, newbee here. What I'm trying to do is to compress files on NTFS from C#. I've been fishing around for info and gathered the hereafter. I'd like to know what's wrong with...
2
by: Michael Allen | last post by:
I would like to perform something similar to the below function in C# .NET. The C++ below code is from a Microsoft DDK sample driver application. Specifically, I would like to perform Device I/O...
0
by: ttan | last post by:
How do I send a buffer down to a driver and receive back a new buffer from that driver? I received the new buffer from the driver but it give me the wrong data. And how do I know if...
0
by: noe | last post by:
I have done a DLL in unmanaged code C++ and in that dll I have defined a function that use memcpy.This dll run ok.I use that dll in a aplication in C# managed code in Visual Studio .NET. I import...
3
by: Jacky | last post by:
Hi, I am trying to make network card interface with VB.NET 2002. I use DeviceIOControl-function. I have tried to define inbuffer and outbuffer using byte array and it's pointer. The second I...
5
by: Lou | last post by:
is there a VB .NET way to use the API "DeviceIoControl"? -Lou
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.