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

Device Driver in VB 2005

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...79&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.

Feb 7 '06 #1
6 1993
>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.GetLastWin3 2Error()
return after the ReadFile call?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 7 '06 #2
Fla

Mattias Sjögren ha scritto:
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.GetLastWin3 2Error()
return after the ReadFile call?


It returns 6. What does it mean?

Thanks



Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Feb 8 '06 #3
>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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 8 '06 #4
Fla

Mattias Sjögren ha scritto:
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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


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.

Feb 8 '06 #5
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.
Feb 8 '06 #6
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

Feb 9 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Wouter van Ooijen | last post by:
I want to use Python to interface with an USB HID device (not a keyboard or mouse, just something that uses the HID driver to avoid the need for a specific driver). Is this possible in pure Python...
2
by: nbhalala | last post by:
Hello Friends, Hi Myself Naresh (B.E. Comp. Eng) from Mumbai... I'm a Linux Device Driver Writer... I would like to learn writing Driver of "USB Devices"...BUT before that I'm presently working...
12
by: Steve | last post by:
I wrote a simple virtual device driver int15.sys, Is C# support load the device driver from AP?
8
by: Tony Liu | last post by:
I am having a "Null Device is Missing" compile error when compiling a c++ project. The documentation from MSDN said it could be caused by low system resource or the user account does not have...
3
by: bb | last post by:
I have a windows network device driver written in c++ and a user interface im porting to c#, my problem is i dont seem to be getting notified of the event calls from the driver to the c# app im...
7
by: Ritu | last post by:
Hi All, Can any body please tell me how i can write a device driver using CSharp. Thanks, Ritu
0
by: am | last post by:
Hi, I have an USB hardware device that came with some (poor) software. I would like to write my own software to use the hardware in dotnet. There are no COM dll's to reference from the...
0
by: Fla | last post by:
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...
1
by: =?Utf-8?B?15DXldeo158=?= | last post by:
I have recently installed my windows XP, the process went smoothly, but I had encounterd some drivers issues after the installation. I managed to solve the ethernet adapter driver issue, but I...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.