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

Visual Basic 2005 CreateFile

Fla
Hy!
I'm a newbie to VB 2005 and I have to connect my program to a driver
previously developed for a custom ISA card.
With my old VB 6 code I used the routine CreateFileA exported from
kernel32 with this defination:

Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal
lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode
As Long, ByVal NULLSecurityAttributes As Long, ByVal
dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long,
ByVal NULLTemplateFile As Long) As Long

The routine was called with

Public hCVxD As Long
hCVxD = CreateFile("\\.\Driver", GENERIC_READ Or GENERIC_WRITE, 0,
sNULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, sNULL)

.... and this code works properly.

I parsed this code with the same args in VB 2005, without getting any
error during build and run-time but hCVxD goes in overflow.
What I'm doing wrong? Does anybody know a solution? Where can I find
any suggestion?

Thanks for your replies.

Feb 6 '06 #1
5 3031
"Fla" <fl********@tiscali.it> schrieb:
I'm a newbie to VB 2005 and I have to connect my program to a driver
previously developed for a custom ISA card.
With my old VB 6 code I used the routine CreateFileA exported from
kernel32 with this defination:

Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal
lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode
As Long, ByVal NULLSecurityAttributes As Long, ByVal
dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long,
ByVal NULLTemplateFile As Long) As Long

The routine was called with

Public hCVxD As Long
hCVxD = CreateFile("\\.\Driver", GENERIC_READ Or GENERIC_WRITE, 0,
sNULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, sNULL)


The declaration is wrong for VB.NET:

\\\
Private Declare Auto Function CreateFile Lib "kernel32.dll" ( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Int32, _
ByVal dwShareMode As Int32, _
ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, _
ByVal dwCreationDisposition As Int32, _
ByVal dwFlagsAndAttributes As Int32, _
ByVal hTemplateFile As IntPtr _
) As IntPtr
....
Dim hDVxD As IntPtr = CreateFile(..., IntPtr.Zero)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Feb 6 '06 #2
Fla,
In addition to Herfried's comments.

http://www.pinvoke.net/ is an excellent resource for finding the .NET
definitions of Win32 APIs.

For example:

http://www.pinvoke.net/default.aspx/kernel32.CreateFile

Is the page what shows CreateFile.

The only "caveat" about pinvoke.net is sometimes it uses the P/Invoke
(DllImport) syntax instead of the Declare syntax, I generally prefer the
Declare syntax. However its relatively easy to convert between the two...
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Fla" <fl********@tiscali.it> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
| Hy!
| I'm a newbie to VB 2005 and I have to connect my program to a driver
| previously developed for a custom ISA card.
| With my old VB 6 code I used the routine CreateFileA exported from
| kernel32 with this defination:
|
| Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal
| lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode
| As Long, ByVal NULLSecurityAttributes As Long, ByVal
| dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long,
| ByVal NULLTemplateFile As Long) As Long
|
| The routine was called with
|
| Public hCVxD As Long
| hCVxD = CreateFile("\\.\Driver", GENERIC_READ Or GENERIC_WRITE, 0,
| sNULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, sNULL)
|
| ... and this code works properly.
|
| I parsed this code with the same args in VB 2005, without getting any
| error during build and run-time but hCVxD goes in overflow.
| What I'm doing wrong? Does anybody know a solution? Where can I find
| any suggestion?
|
| Thanks for your replies.
|
Feb 6 '06 #3
Fla
Thanks you both for the replies.
I tried with your suggestions but I get always the same value for hCVxD
( 312) while, with VB 6 equivalent code I get different values for
hCVxD each time I run my old program. Is it due to .NET framework or am
I doing mistakes?

Thanks

Feb 6 '06 #4
"Fla" <fl********@tiscali.it> schrieb:
I tried with your suggestions but I get always the same value for hCVxD
( 312) while, with VB 6 equivalent code I get different values for
hCVxD each time I run my old program. Is it due to .NET framework or am
I doing mistakes?


I suggest to post the code you are using.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Feb 6 '06 #5
Fla
Ok, thanks for your attention; I checked and fixed the CreateFile code
with an exception. Now I can connect via handle to the the driver, but
I can't read datas from it despite I'm using ReadFile as reported in
the folllowing URL
http://support.microsoft.com/default...79&Product=vb6
The code I'm using, is the following:

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 can't get datas from driver cause I get an exception ("Unable to
read from driver").

What am I doing wrong?

Feb 7 '06 #6

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

Similar topics

6
by: IanHale | last post by:
Is there any way of simply using the COM port from Visual Basic? All the solutions I've found seem to require the use of Visual Studio whereas I only have the the 'basic' version. I'm not after...
2
by: elnahrawi | last post by:
Download ebook http://books-download.com/?Book=1487-Visual+Basic+2005+Jumpstart Okay, all you VB6 developers--time's up. As of March 2005, Microsoft no longer supports this version of Visual...
5
by: Fla | last post by:
Hy! I'm a newbie to VB 2005 and I have to connect my program to a driver previously developed for a custom ISA card. With my old VB 6 code I used the routine CreateFileA exported from kernel32...
4
by: sqlguy | last post by:
Why do we have to contact MS for a problem that has been with this compiler from at least the beta of VS 20005. I am so sick and tired of the 30 - 40 clicks it takes to dismiss VS when there is a...
6
by: Carol | last post by:
Hi. When I try to run Visual Studio 2003 I get the message "MS development environment is not installed for the current user. Please run setup to install the application." Is there any way to...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
3
by: Edwin Smith | last post by:
I have a 2 form project in VS2005 that now hangs whenever I try to do anything with the second form. This seems to have started when I added some SQL tables from a Pervasive v.9 database using the...
11
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I have seen the terms Visual Basic 2005 and VB.NET. It seems that sometimes they seem to be referring to the same thing but sometimes they are not. I also run into terms like VB9 and VB10.
1
by: Deigor | last post by:
Hi i am working on serial port programming using CreateFile function in VC. This function runs well in Visual Studio 6, while the same instruction fail to execute in VS2005. Can any one tell what...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.