Need help with CreateFile API function

J

Jim Flanagan

Hi...
I am using VB.net Express to experiment with the Win32 API functions
that are available. The current project is an application that will
read the raw sectors of a logical drive so that a CRC-32 calculation can
be performed on all of the bytes of the logical drive. This is my first
experience with the CreateFile function.

Here is the problem(s) that I am having.


Here is my declaration of the function in a separate module.
Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" ( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Integer, _
ByVal dwShareMode As Integer, _
ByRef lpSecurityAttributes As Integer, _
ByVal dwCreationDisposition As Integer, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As Integer) As Integer

Here is how I am calling the function:

Simply trying to open a file for reading...

hDevice = CreateFile("C:\Autoexec.bat", GENERIC_READ, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, _
0%, _
OPEN_EXISTING, _
0%, 0%)

Initially, I was having success opening a physical drive using this
function. However, all of a sudden I am now getting a system error:

"The revision level is unknown."

and the function fails.


I'm stumped. If anyone has any suggestions would be appreciated.
Thanks.
-jim
 
J

Jim Flanagan

Here's a program I wrote that makes images of floppy disks, it uses the
CreateFile API. http://boycot.no-ip.com/vb/RawReadWriteFloppy.htm

I used Int32 instead of Integer for types, not sure if that will make a
difference or not, but I used IntPtr for lpSecurityAttributes.

Terry -
I just tried your method of declaring the CreateFile function and it
appeared to resolve my problem. I *think* the problem was not the Int32
definition, but the IntPtr. Everything seems to work OK now.

Thanks for sharing your code example.
Take care
-jim
 

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