This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Call method in a DLL?
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Feb 03, 2010
07:31 AM
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;
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;
(2) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Feb 03, 2010
01:32 PM
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?
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Feb 03, 2010
06:13 PM
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
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