Archive: Problem with kernel32::ReadFile


Problem with kernel32::ReadFile
  I am having a problem with the Windows ReadFile function when executing it with the system.dll plug-in. I am able to open the file and get the file size with the kernel32 functions, so I know that the file handle is valid. When I attempt to read data from the file with the ReadFile Function it always returns 0 indicating failure and 0 bytes read. The GetLastError returns the code file already exists which is probably from when the file was opened with CreateFile. If anyone has an idea as to what might be wrong I would be bery gratefull for a response. The code snippet is below

!define OPEN_EXISTING 3
!define CREATE_NEW 1
!define CREATE_ALWAYS 2

!define FILE_ATTRIBUTES_NORMAL 128
!define GENERIC_WRITE 0x40000000
!define GENERIC_READ 0x80000000

System::Call Alloc 80 ; Allocate memory for read buffer
Pop $0 ; Pointer to Read Buffer

System::Call "kernel32::CreateFile(t '$INSTDIR\$1', ${GENERIC_READ},i 0, i 0, i ${OPEN_EXISTING}, i ${FILE_ATTRIBUTES_NORMAL}, i 0) i .r8"

System::Call "kernel32::GetFileSize(i r8, i 0) i .r6"

System::Call "kernel32::ReadFile(i r8, i r0, i 80, *i .r2, i 0) i .r3"


Chris Lustig


Any reason you are using that instead of FileOpen/FileRead/FileClose?

Stu


Originally posted by Afrow UK
Any reason you are using that instead of FileOpen/FileRead/FileClose?

Stu
I am trying to copy binary CAB files from a PC to a Windows CE device attached to PC with ActiveSync. If FileRead encounters the code for a new line it is going to return and I will not know how many bytes have been read. Also I was allocating memory for a buffer that is bigger than 1024 bytes.

Chris

My guess would be that


System::Call Alloc 80 ; Allocate memory for read buffer 

>
should be changed into

System::Alloc 80 ; Allocate memory for read buffer 

>