cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Johnny_Thunder
Level 3

Using a .dll

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:

InstallScript:

#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;
begin
nResult = UseDLL (My_dll);
if (nResult = 0) then
MessageBox ("UseDLL successful \n\n.DLL file loaded.", INFORMATION);
else
MessageBox ("UseDLL failed.\n\nCouldn't load .DLL file.", SEVERE);
endif;
Hello(); <-----------------------------------------------------------------------DLL function call
if (UnUseDLL (My_dll) < 0) then
MessageBox ("UnUseDLL failed.\n\nDLL still in memory.", SEVERE);
else
MessageBox ("UnUseDLL successful.\n\n.DLL file removed from memory.", INFORMATION);
endif;
end;

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

stdafx.h:

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

HelloWorld.h:
#ifndef HELLOWORLD_H
#define HELLOWORLD_H

__declspec(dllexport) void Hello(void);

#endif

HelloWorld.cpp:
#include "stdafx.h"
#include "HelloWorld.h"

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

I appreciate the help.
Labels (1)
0 Kudos
(5) Replies
RobertDickau
Flexera Alumni

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"
EXPORTS
Hello
0 Kudos
RobertDickau
Flexera Alumni

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.
0 Kudos
Johnny_Thunder
Level 3

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.
0 Kudos
RobertDickau
Flexera Alumni

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.
0 Kudos
Johnny_Thunder
Level 3

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.
0 Kudos