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

Call method in a DLL?

Hello all:

I am trying to call a method in a Windows DLL from InstallScript in an MSI project. I created a very simple dll and called UseDLL in teh script, but it crashes when I try to call the method, and the debugger did not show me anything. Here is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LogUtils
{
public class Class1
{
public void writeMessage(string strMsg)
{
Console.WriteLine(strMsg);
}
}
}

and added the following lines to setup.rul:

prototype VOID LogUtils.writeMessage(STRING);

function WriteEvent(hMSI)
STRING strFolder, strFile, strMsg, tmpFolder;
NUMBER nResult, nResult2, size;
begin
strFolder = "C:\\Temp";
strFile = "johnzServiceSetupLog.log";
strMsg = "Testing from an external DLL";

nResult = MsiGetProperty(hMSI, "SUPPORTDIR", tmpFolder, size);
nResult = UseDLL( tmpFolder ^ "LogUtils.dll" ) ;
if (nResult = 0) then
MessageBox ("UseDLL successful \n\n.dll file loaded.", INFORMATION);
else
MessageBox ("UseDLL failed.\n\nCouldn't load .dll file.", INFORMATION);
abort;
endif;
writeMessage(strMsg);

if (UnUseDLL (tmpFolder ^ "LogUtils.dll") < 0) then
MessageBox ("UnUseDLL failed.\n\n.dll file still in memory.", SEVERE);
else
MessageBox ("UnUseDLL successful.\n\n.dll file removed from memory.", INFORMATION);
endif;
end;
Labels (1)
0 Kudos
(2) Replies
RobertDickau
Flexera Alumni

UseDLL, UnUseDLL, and that kind of prototype are intended for C-callable DLLs. For a .NET DLL, perhaps look at the DotNetCoCreateObject help topic and the topics and examples linked to it?
0 Kudos
Christopher_Pai
Level 16

You can't P/Invoke from unmanaged (InstallScript) to managed ( C# CLR ).

As much as I respect Rob, he's reccomending an InstallShield solution and in this case I would reccomend another one.

http://blog.deploymentengineering.com/2008/07/reasons-dtf-is-better.html
0 Kudos