Archive: Getting DLLs into Setup.EXE


Getting DLLs into Setup.EXE
When I test my installer from a CD or another folder, I am getting an error "The DLL failed to initialize....".

There are 3 helper DLLs that are used by my plugin DLL.

In the script I have lines for each of them like:

....
ReserveFile "libmysql.dll"
....
Function .onInit
...
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "libmysql.dll"
...
FunctionEnd

I thought this would add the dll(s) to the compiled setup.exe program. The goal is to have a single file for distribution.

Do I need to have a File statement for them? I could not find anything the covers this type of dll. If they are already in the $EXEDIR the setup program runs fine.

Thanks,
Jim


SetOutPath $EXEDIR
ReserveFile "libmysql.dll"

No need for MUI_INSTALLOPTIONS_EXTRACT... That's not for what you want.

-Stu


MUI_INSTALLOPTIONS_EXTRACT extracts a file to the plug-ins directory. The plug-ins directory is also where your plug-in is extracted. The problem is the Windows loader doesn't know it has to search for the DLL in there. You need to use SetOutPath to set the current working directory. The loader knows to search there.

SetOutPath $PLUGINSDIR
File libmysql.dll
MyPlugin::SomeFunc

Thank you both, I've tried to implement both your suggestions without success. At one point instead of getting the original error I got a message that the installer was corrupt or virus infected - maybe that was progress? All other combinations resulted in the DLL failed to initialize message.

A stripped down version of my last test is:

;--------------------------------
;Reserve Files
ReserveFile "InstallInfo.ini"
....
ReserveFile "Progress.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
;--------------------------------
Section "Dummy Section" SecDummy

; Tried this, didn't work
; SetOutPath $EXEDIR
; ReserveFile "ivnvi.dll"
; ReserveFile "windblib.dll"
; ReserveFile "libmysql.dll"

; Tried this, didn't work, so tried to save what used to be OUTDIR and then restore that
; still didn't work
StrCpy $R0 $OUTDIR
SetOutPath $PLUGINSDIR
File "ivnvi.dll"
File "windblib.dll"
File "libmysql.dll"
SetOutPath $R0

File /r "Files\Autoip"
File /r "Files\${PROGNAME}"

;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
;====================================================================
Function .onInit
SetPluginUnload alwaysoff
InitPluginsDir
;Extract InstallOptions INI files
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "InstallInfo.ini"
.....
; Tried with and without this commented out.
; !insertmacro MUI_INSTALLOPTIONS_EXTRACT "ivnvi.dll"
....
SetOutPath "$SetupWorkDir"
....
FunctionEnd

Thanks for helping.


Where is the plug-in called in the script? You must have SetOutPath $PLUGINSDIR above it, without any other SetOutPath in the middle.


My plugin is called install6.dll. It is located in the NSIS\Plugins folder.

My plugin has a dependancy on three other DLLs which are not called directly from the NSIS script but which are needed by my plugin dll.

I compile the script with those 3 dlls in the root of the script, and when the resultant.exe is run there everything works.

When I move the resultant.exe to another folder I get the messages.

I actually call my plugin in the leave function of a custom page which occurs immediately after the user selects the install folder.

I tried moving the following into that function but still no change.

SetOutPath $PLUGINSDIR
File "ivnvi.dll"
File "windblib.dll"
File "libmysql.dll"


Do you have any more SetOutPath instructions between that piece of code and the plug-in call itself? Does the plug-in set the current working directory?


I guess some background is needed.

The main NSIS script packages up some files including several other NSIS
output exe files that are located in a directory structure.

In .onInit SetOutPath becomes $SetupWorkDir which is $TEMP\setup

The very first page is MUI_PAGE_INSTFILES.

All the files get extracted to SetupWorkDir, the plugins go deep into
Documents and settings.

The user works his way thru the dialogs. After selecting MUI_PAGE_INSTFILES
a custom page is called having a Start button.

The begins the main installation process which installs several packages.

I have now tried two things in my custom leave function since the last post.

1) Since the SetOutPath was already to my $SetupWorkDir I just let the
files be extracted there. That didn't work, so

2) I SetOutPath to the plugins folder and then set it back to setup, as below.

SetOutPath $PLUGINSDIR
File "ivnvi.dll"
File "windblib.dll"
File "libmysql.dll"
SetOutPath $SetupWorkDir

In summary,

- a custom plugin is in the NSIS\plugins folder
- 3 dependant dlls are in the root of my script folder
- the plugin is extracted to a system $TEMP folder

- I can't get syntax correct to get the 3 dependant dlls where
NSIS expects them to be.

I think the dependant dlls need to land in the plugins folder so
my custom plugin will find them.

The script compiles without errors but when executed the DLL failed to
initialize message is generated.


Put SetOutPath $PLUGINSDIR right above the plug-in call. Don't use SetOutPath $SetupWorkDir before the plug-in call. This will tell the Windows loader where to look for the DLLs.


Thank you all for your help.

I was able to get the dlls to appear in BOTH the $PLUGINSDIR and the $EXEDIR and it still failed.

If however, the dll was in the EXEDIR before launch, it was successful.

Since we plan on distributing by sending one file by FTP, needing two files is not an option. I will continue looking for a solution. ............

...................


...................


Hmmmmmm, sometimes writing helps. It occurred that when the dll gets there by my copy commands its just too late.

At the start of .onInit I added:

SetOutPath $EXEDIR
File "ivnvi.dll"

Viola! The file is extracted at the very start and all is happy. So now I'm only 3 days past deadline:(

But ;) for getting past this issue!

Thanks Kichik and Afrow UK!


Well....
There is one 'minor' problem and hopefully a solution.

When the setup program is copied to a CD-ROM, the attempt to extract the file (dll) to the CD-ROM fails.

I tried changing the SetOutPath to $PLUGINSDIR but that won't work in a regular empty disk folder, let alone a CD.

I suppose one solution would be to leave the SetOutPath to $EXEDIR. On distribution CD's include the dll file. For Web downloads, the file will get extracte to a disk ok.

Does anyone has a better suggestion?


I have found something that works.

On CD distribution disks put the DLL on the CD with the setup program. For ftp distribution, a file is not needed it will be extracted.

Look to see if the file is in the EXEDIR, if it is not, copy it there

In .onInit

FindFirst $0 $1 $EXEDIR\ivnvi.dll
StrCmp $1 "ivnvi.dll" nocopy +1
SetOutPath $EXEDIR
File "ivnvi.dll"
nocopy:

SetPluginUnload alwaysoff
InitPluginsDir

--- Thanks for all the help, I hope this helps someone else.


Use IfFileExists

-Stu