View Full Version : Using a .dll

Johnny Thunder
10-24-2013, 01:01 PM
I am currently using InstallShield 2013 and Visual Studio 2010. I have been attempting to create a .dll file for use with installShield. I am able to load and unload my .dll, but when I try to call the method from the dll, the installer ends abruplty. I have read multiple forums and cannot find a solution. I will post my code below:


#include "ifx.h"
#define My_dll "c:\\users\\...\\documents\\visual studio 2010\\Projects\\HelloWorld\\Debug\\HelloWorld.dll"

prototype cdecl HelloWorld.Hello();
export prototype MyFunction(HWND);

// Function: MyFunction
// Purpose: This function will be called by the script engine when
// Windows(TM) Installer executes your custom action (see the "To
// Do," above).
function MyFunction(hMSI)
NUMBER nResult;
nResult = UseDLL (My_dll);
if (nResult = 0) then
MessageBox ("UseDLL successful \n\n.DLL file loaded.", INFORMATION);
MessageBox ("UseDLL failed.\n\nCouldn't load .DLL file.", SEVERE);
Hello(); <-----------------------------------------------------------------------DLL function call
if (UnUseDLL (My_dll) < 0) then
MessageBox ("UnUseDLL failed.\n\nDLL still in memory.", SEVERE);
MessageBox ("UnUseDLL successful.\n\n.DLL file removed from memory.", INFORMATION);

Incase you can help debug my C++, Here is what I modified:

// TODO: reference additional headers your program requires here
#include "HelloWorld.h"


__declspec(dllexport) void Hello(void);


#include "stdafx.h"
#include "HelloWorld.h"

void Hello()
MessageBox( NULL, TEXT("Hello World"),
TEXT("In a DLL"), MB_OK);

I appreciate the help.

10-24-2013, 05:06 PM
If you have a copy of Dependency Walker or the dumpbin tool that ships with Visual Studio, is the "Hello" function exported? For example, if you run dumpbin /exports HelloWorld.dll, does Hello show up?

If not, you might try adding a .def file to your VS project: add a text file called HelloWorld.def, with contents:

LIBRARY "HelloWorld"

10-24-2013, 05:09 PM
Also, is this an InstallScript project or a Windows Installer project? If it's MSI, you might try creating a DLL you can call directly as a custom action, rather than doing it in two steps.

Johnny Thunder
10-28-2013, 06:25 AM
The project I am using is a Basic MSI project, I tried to use the UseDLL() method and also tried to create a custom action for the dll. In creating a custom action, the method doesn't show up in the method browser when I click on the ellipse. I also tried depenpancy walker and the function signature does show up.

10-28-2013, 07:36 AM
The InstallShield help topic "Calling Functions in Windows Installer DLL Files" has a short walkthrough that might be useful. It has an example of the function signature that a DLL you call directly from a custom action wants.

Johnny Thunder
10-28-2013, 08:02 AM
I read this tutorial http://www.ni.com/white-paper/3056/en/#toc1 which showed how to go into the project properties and set the linker to look for the .def file that you suggested I create and I got it to work. Thanks so much for your help.