
Originally Posted by
Niya
If you're still having trouble, feel free to post you ReadFile code and we can help you out.
my code to read the whole content of small files:
Code:
Public Declare Function CreateFileWide Lib "kernel32" Alias "CreateFileW" (ByVal lpFileName As Long, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Public Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
Dim hFile As Long
Dim BytesRead As Long
Dim BufferLen As Long
Dim bBuffer() As Byte
Dim sText as String
hFile = CreateFileWide(StrPtr(sFile), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0)
ReadFile(hFile, bBuffer(0), lBufferLen, lBytesRead, 0)
sText = StrConv(bBuffer, vbUnicode)
...
The files i read can be encoded with ANSI, Unicode or UTF8. I checked the encoding with notepad.
Maybe i read the file content directly into a string variable using:
Code:
ReadFile(hFile, StrPtr(sText), lBufferLen, lBytesRead, 0)