cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
ShaimaaMohammad
Level 4

Calling a .dll File Function

Hi all
I have made an Install script file as following

//----------------------------------------------------------------------------
#include "ifx.h"
// The keyword export identifies MyFunction() as an entry-point function.
// The argument it accepts must be a handle to the Installer database.


prototype void AddToReg.AddtoRegistry(BYREF STRING);
export prototype MyFunction(HWND);

function MyFunction(hMSI)
NUMBER nResult;
STRING path;
begin
path = INSTALLDIR;
UseDLL (SUPPORTDIR ^ "AddToReg.dll");
MessageBox ("UseDLL successful \n\n.dll file loaded.", INFORMATION);
MessageBox(path, INFORMATION);
AddToReg.AddtoRegistry(path);//-------------> This line doesn't executed
MessageBox("AddToReg", INFORMATION);
MessageBox(path, INFORMATION);
UnUseDLL (SUPPORTDIR ^ "AddToReg.dll");
MessageBox ("UnUseDLL successful.\n\n.dll file removed from memory.", INFORMATION);
end;
//--------------------------------------------------------------------------------

Is the following line true?

DLLName.FunctionName(parameter)
AddToReg.AddtoRegistry(path);//-------------> This line doesn't executed

Thank You in advance
Labels (1)
0 Kudos
(5) Replies
RobertDickau
Flexera Alumni

Does the UseDLL call succeed? In an MSI project, the SUPPORTDIR property is different from the SUPPORTDIR variable, so perhaps try getting the property value instead?
0 Kudos
ShaimaaMohammad
Level 4

RobertDickau wrote:
Does the UseDLL call succeed? In an MSI project, the SUPPORTDIR property is different from the SUPPORTDIR variable, so perhaps try getting the property value instead?


First.. Thank you for your help.
I am using Basic MSI Project. I tried to debug the project and the UseDLL call succeeded.

But I don't know how to call a method from thd dll?
I followed the steps were in the InstallShield Help.

What is the difference between SUPPORTDIR as variable and SUPPORTDIR as property?

Thank You in advance
0 Kudos
ShaimaaMohammad
Level 4

Sorry I modified the code to be as the code attached in the file
because the 1st didn't load the dll into memory.
0 Kudos
RobertDickau
Flexera Alumni

The help topic "SUPPORTDIR" gives some information about the difference between the property and the variable.

What type of DLL is it? (You might post a skeleton inside [code] and [/code] tags.) If it's a C-callable DLL, you can use that type of prototype with UseDLL. For COM methods there's CoCreateObject, and for .NET methods there's DotNetCoCreateObject...
0 Kudos
ShaimaaMohammad
Level 4

Thank You for help and for this important Note which I didn't know:)
I tried the following code but it also doesn't work 😞

[code]
function MyFunction(hMSI)
// To Do: Declare local variables.
string simpleMessage,dllPath,className;
object myDLLObj;
STRING path;
OBJECT oObj;
NUMBER nResult, nvBufferSize;
STRING sDLL;
STRING svSupportDir[MAX_PATH];

NUMBER cchValueBuf;
STRING szWinDomain,szWinUser,szWinPass;


begin

// To Do: Write script that will be executed when MyFunction is called.

path = INSTALLDIR;
nvBufferSize = MAX_PATH;
try
MsiGetProperty(hMSI, "SUPPORTDIR", svSupportDir, nvBufferSize);


catch
SprintfBox( WARNING,"Error", "MsiGetProperty(SUPPORTDIR) failed with error %s", FormatMessage( Err.Number ) );
return -1;
endcatch;


sDLL = svSupportDir ^ "ManagedDLL.dll";
//sDLL = SUPPORTDIR ^ "AddToReg.dll";
if(UseDLL( sDLL )= 0)then
MessageBox("Thanks", INFORMATION);
endif;


//nResult = UseDLL(SUPPORTDIR^"ManagedDLL.dll");

//if(nResult = 0)then
//MessageBox("Loaded",INFORMATION);
//else
//MessageBox("Failed to be Loaded",INFORMATION);
//endif;

dllPath = SUPPORTDIR ^ "ManagedDLL.dll";

MessageBox("Path to DLL: " + dllPath,INFORMATION);
className = "MyClass";

//------------------------- Shaimaa -------------------------//
//Gets the domain
cchValueBuf = 512;
nResult = MsiGetProperty(hMSI, "WINDOMAINNAME", szWinDomain, cchValueBuf);

//Gets the user
cchValueBuf = 512;
nResult = MsiGetProperty(hMSI, "WINUSERNAME", szWinUser, cchValueBuf);

//Gets the password
cchValueBuf = 512;
nResult = MsiGetProperty(hMSI, "WINUSERPASSWORD", szWinPass, cchValueBuf);

//Test all properties
MessageBox("Domain name :"+ szWinDomain + " User name : " + szWinUser+ " Password : " +szWinPass, INFORMATION);
//------------------------- Shaimaa -------------------------//

try
//set myDLLObj = DotNetCoCreateObject(dllPath,className,"");
MessageBox(sDLL,INFORMATION);
//set myDLLObj = DotNetCoCreateObject(sDLL,className,"");
set myDLLObj = DotNetCoCreateObject(sDLL,"ManagedDLL.MyClass","");

catch

MessageBox(Err.Number , SEVERE);
//MessageBox("It finally worked....",INFORMATION);
endcatch;
// myDLLObj.log();
myDLLObj.MyFunc();
end;

[/code]

Error No. -2147219705 appears ... I don't know what is the problem.
Thank You in advance.
0 Kudos