xplct0
20th May 2008 01:15 UTC
Need help with callbacks
I'm trying to make use of CopyFileEx. Here's the MSDN ref: http://msdn.microsoft.com/en-us/library/aa363852.aspx
I can't figure out why none of my callback's params are being properly filled out. I'm also not sure if I'm setting this up correctly in the first place -- I'm slightly confused by the documentation. The only parameter that seems to get filled out with anything cogent is: dwStreamNumber, which is set to 1, and according to MSDN, it's "A handle to the current stream. The first time CopyProgressRoutine is called, the stream number is 1." Great. But every thing else seems to be NULL, even though the file does get copied over properly. (the file is > 0 bytes) If anyone can help that'd be great. Thanks!
Code
#(0) __in LARGE_INTEGER TotalFileSize,
#(1) __in LARGE_INTEGER TotalBytesTransferred,
#(2) __in LARGE_INTEGER StreamSize,
#(3) __in LARGE_INTEGER StreamBytesTransferred,
#(4) __in DWORD dwStreamNumber,
#(5) __in DWORD dwCallbackReason,
#(6) __in HANDLE hSourceFile,
#(7) __in HANDLE hDestinationFile,
#(8) __in_opt LPVOID lpData
System::Get "(i .r0, i .r1, i .r2, i .r3, i .r4, i .r5, i .r6, i .r7, i .r8) isR0"
System::Call 'kernel32::CopyFileEx(t "C:/from/test.txt", t "c:/to/test.txt", k r0, i 0, i 0, i 1) i .r3'
loop:
StrCmp $R0 "callback1" 0 done
Goto loop
done:
MessageBox MB_OK $0
MessageBox MB_OK $1
MessageBox MB_OK $2
MessageBox MB_OK $3
MessageBox MB_OK $4
MessageBox MB_OK $5
MessageBox MB_OK $6
MessageBox MB_OK $7
MessageBox MB_OK $8
Anders
20th May 2008 02:42 UTC
your stuff is all messed up, you need to use L for 64 bit numbers etc...
this seems to work tho:
SetPluginUnload alwaysoff
System::Get "(l.R0,l,l.R1,l,i.R2,i.R3,i,i,i)isr1"
pop $0
System::Call 'kernel32::CopyFileEx(t "$temp\Temp.exe", t "$temp\dest.txt",k r0,i,i,i)i.r9'
loop:
StrCmp $1 "callback1" 0 done
DetailPrint "cb: totsize=$R0|strmsize=$R1|strmid=$R2|cbreason=$R3"
Push 0 # return value of the callback
StrCpy $1 "" # clear $R0 in case there are no more callback calls
System::Call $0 # tell system to return from the callback
Goto loop
done:
SetPluginUnload manual
DetailPrint CopyFileEx($0)ret=$9
System::Free $0
nsis already supports file copy, not sure why you are doing this
xplct0
20th May 2008 04:00 UTC
AGGGHHH FINALLY! I got it working!! Thanks for the cb help, Anders.
So everyone kept saying it wasn't possible to display billboards based on %copy complete, which is just silly if you have access to the win32. I know this is sloppy, but I just got it working:
!include 'MUI.nsh'
!include 'Image.nsh'
!define AppName `Sand`
Name '${AppName}'
OutFile 'Sandbox.exe'
InstallDir '$PROGRAMFILES\${AppName}'
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
#Dumpstate::debug
# Fix the rukus vista has been causing with shortcut removals.
RequestExecutionLevel admin
Section 'CD_ONE'
strcpy $9 'ladeda'
SetPluginUnload alwaysoff
System::Get "(l,l.R1,l,l,i,i,i,i,i)isr1"
pop $0
System::Call 'kernel32::CopyFileEx(t "c:\from\test.txt", t "c:\to\test.txt",k r0,i,i,i)i.r9'
loop:
StrCmp $1 "callback1" 0 done
IntCmp $R1 40000000 0 lessthan40mb morethan40mb
lessthan40mb:
strcmp $9 '0' doneCmp +1
!insertmacro DisplayImage 'c:\Bilboard0.bmp'
strcpy $9 '0'
Goto doneCmp
morethan40mb:
strcmp $9 '1' doneCmp +1
!insertmacro DisplayImage 'c:\Bilboard1.bmp'
strcpy $9 '1'
Goto doneCmp
doneCmp:
Push 0 # return value of the callback
StrCpy $1 "" # clear $R0 in case there are no more callback calls
System::Call $0 # tell system to return from the callback
Goto loop
done:
SetPluginUnload manual
System::Free $0
SectionEnd
Afrow UK
20th May 2008 11:47 UTC
That could be tidied up quite nicely using some LogicLib.
Stu