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

Parameters in DeviceIoControl in VB.NET

P: n/a

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 tried
AllocHGlobal and Copy.

They works nice though the old app set these parameters to heap and VB.NET
to programs reserved memory area.

I get windows error 31.

Any suggestion??

Thanks in Advance,
Jacky
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hello,

"Jacky" <ja******@hotmail.com> schrieb:
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 tried
AllocHGlobal and Copy.

They works nice though the old app set these parameters to heap
and VB.NET to programs reserved memory area.

I get windows error 31.


Posting code will make finding the error easier.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2

P: n/a

This C code works:
UCHAR inBuffer[1024];
UCHAR outBuffer[1024];
....

inBuffer[0] = 0x01;
inBuffer[1] = 0x01;
inBuffer[2] = 0x01;
inBuffer[3] = 0x01;

outBuffer[0] = 0x00;
outBuffer[1] = 0x00;
outBuffer[2] = 0x00;
outBuffer[3] = 0x01;

if (DeviceIoControl(handle,
157330,
(LPVOID) &inBuffer[0],
sizeof(inBuffer),
(LPVOID) &outBuffer[0],
sizeof(outBuffer),
&dwBytesReturned,
NULL))

But VB.Net not. It do not bush buffers to stack

<DllImport("kernel32.dll", SetLastError:=True)> _
Private Function DeviceIoControl(ByVal deviceHandle As IntPtr, _
ByVal ioControlCode As Int32, _
ByVal inBuffer As IntPtr, _
ByVal inBufferSize As Int32, _
<Out()> ByVal outBuffer As IntPtr, _
ByVal outBufferSize As Int32, _
ByRef bytesReturned As Int32, _
ByVal overlapped As IntPtr) As Boolean
End Function
....
Dim bufferIn() As Byte = New Byte(3) {}
Dim bufferOut() As Byte = New Byte(3) {}
....
bufferIn(0) = &H1
bufferIn(1) = &H1
bufferIn(2) = &H1
bufferIn(3) = &H1
bufferOut(0) = &H0
bufferOut(1) = &H0
bufferOut(2) = &H0
bufferOut(3) = &H1

Dim inPtr As IntPtr = Marshal.AllocHGlobal(4)
Marshal.Copy(bufferIn, 0, inPtr, 4)

Dim outPtr As IntPtr = Marshal.AllocHGlobal(4)
Marshal.Copy(bufferOut, 0, outPtr, 4)

ok = DeviceIoControl(handle, _
&H170002, _
inPtr, _
bufferIn.Length, _
outPtr, _
bufferOut.Length, _
ret, _
IntPtr.Zero)
Nov 20 '05 #3

P: n/a
if (DeviceIoControl(handle,
157330, [...]ok = DeviceIoControl(handle, _
&H170002, _


&H170002 = 1507330
&H26692 = 157330

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.