Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 10th May 2010, 18:21   #1
santana108
Junior Member
 
Join Date: Apr 2010
Posts: 14
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
santana108 is offline   Reply With Quote
Old 10th May 2010, 18:28   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
Any reason you are using that instead of FileOpen/FileRead/FileClose?

Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 10th May 2010, 18:44   #3
santana108
Junior Member
 
Join Date: Apr 2010
Posts: 14
Quote:
Originally Posted by Afrow UK View Post
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
santana108 is offline   Reply With Quote
Old 10th May 2010, 21:13   #4
f0rt
Junior Member
 
Join Date: Jul 2009
Posts: 33
My guess would be that
PHP Code:
System::Call Alloc 80 Allocate memory for read buffer 
should be changed into
PHP Code:
System::Alloc 80 Allocate memory for read buffer 
f0rt is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump