View Full Version : Calling function inside C# DLL

12-08-2008, 09:19 AM
I am currently working on a project that requires me to:
1. Get a string from the user.
2. Use a function inside a DLL written in C# to modify that string.
<ModString> function ( <UnModString> )
3. Write the modified string into a .config file.
I've had no problem implementing #1 and #3, but I have not been able to implement #2. I have tried to implement a custom action that calls a standard DLL and I get a "the dll being called encountered a problem" error. I have also tried using the UseDll function inside a installscript custom action and I get a "unable to load a dll" error. I am implementing this in a basic msi project using InstallShield 2008. Any ideas or guidance will be greatly appreciated.


12-08-2008, 12:02 PM
Managed Code DLLs, such as those written in C#, cannot be loaded through conventional C++ DLL loading means. From InstallScript code you can load them with DotNetCoCreateObject / CoCreateObjectDotNet. In InstallShield 2009, Basic MSI projects also support calling them in "Managed Code" custom actions.

Christopher Painter
12-08-2008, 12:06 PM
A dash of single responsibility principal would help here.

For #1, just use an MSI dialog; no custom action is required
For #2, a custom action may be required
For #3, I'm guessing config is .config ( xml ) so use XML File Changes view.

For #2, how complex is the customization? Does it require managed code? If so, I'd write a DTF CA reads the property the user inputted and writes it to another property that the XML file changes can use to write out to the config file.

12-08-2008, 01:40 PM
Thanks for the quick replies,

Let me explain things a little better, for the second requirement, once I get a string from the user I am going to pass this string to a public method of a class that resides inside the C# DLL. This method will return a modified string, which will get written to a .config(XML) file. I don't know what is a DTF custom action could you please explain?

Christopher Painter
12-08-2008, 02:51 PM


and then read:


Basically you'd write a DTF custom action in C# that encapsulates your existing class.