A
Andrew Clark
Hello,
Thanks for all replies on this subject. I still cannot get CreateFile to
retun a good value though. I went to PInvoke.net and saw the VB.NET
declaration of this function:
<DllImport("kernel32.dll", SetLastError:=True)> Private Shared Function
CreateFile(ByVal lpFileName As String, ByVal dwDesiredAccess As
EFileAccess, ByVal dwShareMode As EFileShare, ByVal lpSecurityAttributes
As IntPtr, ByVal dwCreationDisposition As ECreationDisposition, ByVal
dwFlagsAndAttributes As EFileAttributes, ByVal hTemplateFile As IntPtr)
As IntPtr
End Function
VB.NET did not like the 'Private Shared' part, so I changed that to
'Public', and all the EFile* types I changed to Integer, so this is what
I end up with:
<DllImport("kernel32.dll", SetLastError:=True)> Public Function
CreateFile(ByVal lpFileName As String, ByVal dwDesiredAccess As Integer,
ByVal dwShareMode As Integer, ByRef lpSecurityAttributes As IntPtr, ByVal
dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer,
ByVal hTemplateFile As IntPtr) As IntPtr
End Function
Now VB.NET does not complain at least. I put a break on this statement:
hFile = CreateFile(FileName, GENERIC_READ, 0, IntPtr.Zero, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, IntPtr.Zero)
and the values are as following:
GENERIC_READ -2147483648
IntPtr.Zero 0
OPEN_EXISTING 3
FILE_ATTRIBUTE_NORMAL 128
but still I get -1 returned! Thoughts?
Thanks,
Andrew
Thanks for all replies on this subject. I still cannot get CreateFile to
retun a good value though. I went to PInvoke.net and saw the VB.NET
declaration of this function:
<DllImport("kernel32.dll", SetLastError:=True)> Private Shared Function
CreateFile(ByVal lpFileName As String, ByVal dwDesiredAccess As
EFileAccess, ByVal dwShareMode As EFileShare, ByVal lpSecurityAttributes
As IntPtr, ByVal dwCreationDisposition As ECreationDisposition, ByVal
dwFlagsAndAttributes As EFileAttributes, ByVal hTemplateFile As IntPtr)
As IntPtr
End Function
VB.NET did not like the 'Private Shared' part, so I changed that to
'Public', and all the EFile* types I changed to Integer, so this is what
I end up with:
<DllImport("kernel32.dll", SetLastError:=True)> Public Function
CreateFile(ByVal lpFileName As String, ByVal dwDesiredAccess As Integer,
ByVal dwShareMode As Integer, ByRef lpSecurityAttributes As IntPtr, ByVal
dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer,
ByVal hTemplateFile As IntPtr) As IntPtr
End Function
Now VB.NET does not complain at least. I put a break on this statement:
hFile = CreateFile(FileName, GENERIC_READ, 0, IntPtr.Zero, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, IntPtr.Zero)
and the values are as following:
GENERIC_READ -2147483648
IntPtr.Zero 0
OPEN_EXISTING 3
FILE_ATTRIBUTE_NORMAL 128
but still I get -1 returned! Thoughts?
Thanks,
Andrew