Calling C# DLL from script

Got a problem you cannot solve? Try here.
damjan
Posts: 12
Joined: Thu Jul 10, 2014 7:04 am

Calling C# DLL from script

Postby damjan » Wed Mar 30, 2016 5:31 pm

Hi guys

After some research I have managed to create a C# assembly with one class that has one method. This method can be called directly from an InstallAware script. This method allows you to use unicode characters for all parameters and also allows you also to return values through the parameters back to the InstallAware script. In case any of you guys are interested in this I added all the things you need in the sample that is attached below.

callingCSharp.zip
(6.77 MiB) Downloaded 648 times


There are two folders in this sample. Each for its own project.

The CSharpDLL folder is the C# solution which has only one class and only one method. This method is called TestMethod. It is exported with an Attribute like the C++ native methods. For this to work the project includes the NUget UnmanagedExports package which is referenced in the project references. Here is what the method looks like:

Code: Select all

[DllExport("TestMethod", CallingConvention = CallingConvention.StdCall)]
public static int TestMethod(string parameter1, string parameter2, IntPtr returnParameter1, IntPtr returnParameter2)

The first two parameters are only passed to the TestMethod, while the last two parameters also return a value back to the InstallAware script. The method also returns an integer.


The IASetup is the InstallAware project that calls the CSharpDLL.dll and its TestMethod. There is only one line that executes the call. The variables that are defined before are used to demonstrate that the method is capable of displaying regular and uni-code characters. The setup requires that the CSharpDLL.dll file is located in the same folder as the .mpr project file. Here is what the Call DLL command looks like:
CallToCSharpDLL.jpg
CallToCSharpDLL.jpg (31.09 KiB) Viewed 5915 times


Give it a try to see if it will work for you.

Regards, Damjan

bokkie
Posts: 767
Joined: Sun Feb 08, 2009 6:30 am

Re: Calling C# DLL from script

Postby bokkie » Thu Mar 31, 2016 2:56 am

Thanks Damjan. I'll download it and try it out. I'll let you know if I have any problems compiling it and using it in a test IA project.
Peter. Smartly dressed, he still resembles an unmade bed.
InstallAware MVP

FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Calling C# DLL from script

Postby FrancescoT » Thu Mar 31, 2016 10:31 am

I'll try it out and I let you know.

Regards
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE

g3ro81
Posts: 1
Joined: Thu Sep 15, 2016 8:50 am

Re: Calling C# DLL from script

Postby g3ro81 » Thu Sep 15, 2016 10:11 am

Hi,
thank you. It works, but i can't run the "Call DLL Function" twice.

For example, this code doesn't work; the first call ends correctly, but the second one doesn't and the installation process doesn't procede.

Code: Select all

Call DLL Function $SUPPORTDIR$\CSharpDLL.dll->TestMethod (get result into variable NUMERICRETURN)
Call DLL Function $SUPPORTDIR$\CSharpDLL.dll->TestMethod (get result into variable NUMERICRETURN)


I tried to add a new method, a new class, a new dll, but the result is the same. Also this code doesn't work.

Code: Select all

Call DLL Function $SUPPORTDIR$\CSharpDLL.dll->TestMethod (get result into variable NUMERICRETURN)
Call DLL Function $SUPPORTDIR$\CSharpDLL2.dll->TestMethod2 (get result into variable NUMERICRETURN2)


You can test this bug using your sample:
- run installer
- click NEXT ("call DLL" works)
- click BACK
- click NEXT again ("call DLL" doesn't work)

Do you experience the same bug?

Thank you

FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Calling C# DLL from script

Postby FrancescoT » Mon Sep 19, 2016 11:30 am

It looks that the DLL cannot be called twice or better, the DLL fails to be loaded after its first call.

Regards
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 174 guests