G
Guest
Hi, All
I am using Windows XP, VS .NET 2003 Windows CE Device platform, i am trying
to convert my application from eVB to VB .NET:
I need to use CreateFile(), GetFileSize, SetFilePointer(), ReadFile(),
CloseHandle()
CreateFile return file handle sometimes negative large number or positive
when i use Err.LastDLLError to check error it is 183 "Cannot create a file
when that file already exists" and GetLastError() returns "-2147482643".
Please, any advice why it is not as easy as in eVB ? see my code below:
Public Const GENERIC_READ = &H80000000
Public Const OPEN_EXISTING = 3
Public Const FILE_BEGIN = 0
<DllImport("coredll.dll", EntryPoint:="CreateFileW", SetLastError:=True)> _
Public Shared Function CreateFile(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, _
ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As
Integer, _
ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer)
As Integer
End Function
sPath = "\Program Files\PTSCOF.DAT"
If rFile.Exists(sPath) = True Then
fHandle = CreateFile(sPath, GENERIC_READ, 0, 0,
OPEN_EXISTING, 0, 0)
lerr = Err.LastDllError
If fHandle <> 0 Then
lsize = GetFileSize(fHandle, 0)
If lsize > 0 Then
outBuffer = New String(CChar(" "), lsize)
SetFilePointer(fHandle, 0, 0, 0)
ReadFile(fHandle, outBuffer, lsize, dwRead, 0)
pos = InStr(1, outBuffer, sSearch, CompareMethod.Text)
End If
If CloseHandle(fHandle) = True Then
End If
End If
I am using Windows XP, VS .NET 2003 Windows CE Device platform, i am trying
to convert my application from eVB to VB .NET:
I need to use CreateFile(), GetFileSize, SetFilePointer(), ReadFile(),
CloseHandle()
CreateFile return file handle sometimes negative large number or positive
when i use Err.LastDLLError to check error it is 183 "Cannot create a file
when that file already exists" and GetLastError() returns "-2147482643".
Please, any advice why it is not as easy as in eVB ? see my code below:
Public Const GENERIC_READ = &H80000000
Public Const OPEN_EXISTING = 3
Public Const FILE_BEGIN = 0
<DllImport("coredll.dll", EntryPoint:="CreateFileW", SetLastError:=True)> _
Public Shared Function CreateFile(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, _
ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As
Integer, _
ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer)
As Integer
End Function
sPath = "\Program Files\PTSCOF.DAT"
If rFile.Exists(sPath) = True Then
fHandle = CreateFile(sPath, GENERIC_READ, 0, 0,
OPEN_EXISTING, 0, 0)
lerr = Err.LastDllError
If fHandle <> 0 Then
lsize = GetFileSize(fHandle, 0)
If lsize > 0 Then
outBuffer = New String(CChar(" "), lsize)
SetFilePointer(fHandle, 0, 0, 0)
ReadFile(fHandle, outBuffer, lsize, dwRead, 0)
pos = InStr(1, outBuffer, sSearch, CompareMethod.Text)
End If
If CloseHandle(fHandle) = True Then
End If
End If