Device Driver in VB 2005

F

Fla

Hy!
I'm newbie to VB 2005 and I'm trying to read value from a device
driver, as I used in VB6 with CreateFile and DeveiceIoControl. I get a
correct driver handle with CreateFile but I can't read values with
ReadFile, as reported in this URL
http://support.microsoft.com/default.aspx?scid=kb;en-us;823179&Product=vb6

I tried with ReadFile with the following code lines:

Try
Success = ReadFile(hSerialPort, Buffer, BytesWritten,
BytesRead, IntPtr.Zero)
If Success = False Then
Throw New CommException("Unable to read from driver")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
End Try

but I couldn't get values from device driver 'cause I get an exception
("Unable to
read from driver").

Is it better DeviceIoControl? What am I doing wrong?

Thanks for your replies.
 
M

Mattias Sjögren

but I couldn't get values from device driver 'cause I get an exception
("Unable to
read from driver").

What does System.Runtime.InteropServices.Marshal.GetLastWin32Error()
return after the ReadFile call?


Mattias
 
F

Fla

Mattias Sjögren ha scritto:
What does System.Runtime.InteropServices.Marshal.GetLastWin32Error()
return after the ReadFile call?

It returns 6. What does it mean?

Thanks
 
M

Mattias Sjögren

It returns 6. What does it mean?

It means "The handle is invalid". Have you verified that CreateFile
really returns a valid handle? What's the type of hSerialPort?


Mattias
 
F

Fla

Mattias Sjögren ha scritto:
It means "The handle is invalid". Have you verified that CreateFile
really returns a valid handle? What's the type of hSerialPort?


Mattias

No, it returned an invalid handle and I've already fixed the code for
it, but I still haven't found a solution for ReadFile 'cause I get
"LastWin32Error 1: Incorrect function".

Try
Success = ReadFile(hCVxD, Buffer, BytesWritten, BytesRead,
IntPtr.Zero)
If Success = False Then
Throw New CommException("Unable to read from driver")
Else
TextBox3.Text = CStr(BytesRead)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

What am I doing wrong?
According .NET, which is better: DeviceIoControl, as in VB6, or
ReadFile?

Thanks for your replies.
 
D

Dick Grier

Is this a serial port device? If so, why not use System.IO.Ports?

Personally, I want more information about what it is that you are REALLY
trying to do before suggesting what might be the problem/solution.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition, ISBN 1-890422-28-2, Mabry Publishing (391 pages, includes CD-ROM).
July 2004.
See www.hardandsoftware.net for details and contact information.
 
F

Fla

Dick Grier ha scritto:
Is this a serial port device? If so, why not use System.IO.Ports?

Personally, I want more information about what it is that you are REALLY
trying to do before suggesting what might be the problem/solution.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition, ISBN 1-890422-28-2, Mabry Publishing (391 pages, includes CD-ROM).
July 2004.
See www.hardandsoftware.net for details and contact information.

I'm trying to read values from an ISA card.

Thanks for your attention
 

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