pgpatron
16th February 2004 17:40 UTC
Delete some exe and dll files during install process
Hi all,
I am using an exe file and a dll file during the install process and I want to delete them once their taks are finished.
I copy them to $INSTDIR and I want to erase them after they have been used.
In my "Delete" call I received an error and the files left in the $INSTDIR after install process is finished.
more or less:
SetOutPath "$INSTDIR"
File /r "${SRC}\*.*"
System::Call 'mydll::AFunctionOfMyFile.dll ...'
Delete mydll.dll
(ERROR Flag on)
ExecWait myexe.exe
Delete myexe.exe
(ERROR Flag on)
Does anyone knows why I can not erase them and/or how should I do it correctly?
Thank you in advance,
Pedro
VegetaSan
16th February 2004 18:34 UTC
Try this
SetOutPath "$INSTDIR"
File /r "${SRC}\*.*"
System::Call 'mydll::AFunctionOfMyFile.dll ...'
Delete "mydll.dll"
(ERROR Flag on)
ExecWait "$INSTDIR\myexe.exe"
Delete "myexe.exe"
(ERROR Flag on)
Please tell me if it works :)
pgpatron
16th February 2004 18:45 UTC
It does not work. Both files are blocked by the installer program... What can I do? :( :(
VegetaSan
16th February 2004 18:53 UTC
What's the error??
pgpatron
16th February 2004 19:06 UTC
I have achieved to fix the problem with the exe file by calling the Delete inside the .onGUIend function inspite of doing it just after its Execwait call.
But that does not work with the DLL System::Call. It is still blocked by the install process whe that function is called.
Help please.
I have bee following the C.5 Calling an external DLL using the System.dll plugin page of the NSIS manual
Inside this page a comment of the example says:
; last plugin call must not have /NOUNLOAD so NSIS will be able to delete
; the temporary DLL
That is what I want to do: Delete the DLL. But I do not understand the meaning of this comment. I have tried with the 'SetPluginUnload manual' and without it and with 'System::Free 0' and without it.
Could you help me please?
Thanks.
Pedro
pgpatron
17th February 2004 09:51 UTC
I have found in the NSIS System Plugin(c) documentation the following option:
u - unload DLL after call (using FreeLibrary, so you'll be able to do something with it, delete for example)
DELETE FOR EXAMPLE!!! Great!! That's what I want to do!
But there is no example (I neither didn't find in forum) and the doc is not very clear for my understanding.
Could somebody show me an example of how to do a System::Call to a DLL with this option?
Thank you all,
pgpatron
17th February 2004 09:58 UTC
Fixed :D
I have already fixed the problem.
:D :D
Maybe It could help somebody:
StrCpy $9 "$INSTDIR\${MYPROGRAM}"
System::Call 'mydll::myfunc(t) i (r9) r8 ? u'
SetPluginUnload manual
System::Free 0
Delete mydll.dll
It runs!!! :) :)
EnCey
20th March 2008 10:31 UTC
I'm facing the same problem, but unfortunately the above solution doesn't work for me...
Here's my code:
StrCpy ${errorText} ""
DetailPrint "Executing ${function} ..."
; load dll
System::Call "kernel32::LoadLibrary(t '${dll}') i .r0 ? e"
IntCmp $0 0 callWebCAError_${LN} callWebCAError_${LN} 0
; get function address
System::Call "kernel32::GetProcAddress(i r0, t '${function}') i .r1 ? e"
IntCmp $1 0 callWebCAError_${LN} callWebCAError_${LN} 0
; call function
System::Call "::$1(${arg}) i .r2 ? e"
IntCmp $2 0 callWebCAError_${LN} callWebCAError_${LN} 0
goto callWebCASuccess_${LN}
callWebCAError_${LN}:
IntCmp $0 0 0 0 +2
DetailPrint "Can't load library $\"${dll}$\"!"
IntCmp $1 0 0 0 +2
DetailPrint "Function $\"${function}$\" not found!"
Pop $0
StrCmp $0 "" 0 +2
StrCpy $0 "[NSIS] Unknown Error"
StrCpy ${errorText} "Error: ${function} failed (Error: $0)"
DetailPrint ${errorText}
goto callWebCAFinish_${LN}
callWebCASuccess_${LN}:
DetailPrint "Successfully executed ${function}! (return value: $2)"
callWebCAFinish_${LN}:
System::Call "kernel32::FreeLibrary(i r0) b s ?e"
ClearErrors
I can't delete the dll, it's locked.
SetPluginUnload manual
System::Free 0
before deletion doesn't work either.
I'm extracting the dll before using it and try to delete it afterwards, both in install and uninstall sections
kichik
20th March 2008 19:14 UTC
Your FreeLibrary call is invalid as `b` is not a valid type. You should use `i` instead.
And this entire piece of code can be replaced by a single System::Call line as it will load the library and find the proc for you.
System::Call "${dll}::${function}(i ${arg}) ?u"
Notice the added "?u" that causes System to call FreeLibrary immediately after the call.
EnCey
21st March 2008 08:44 UTC
Omg shame on me ^^
I was reading the code again and again and never noticed....
I've tried to replace all the code with the single line of code after I've read the first post in this thread, but had some errors. I'll try later when I've more time.
Thanks kichik!