Call .NET DLL methods plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 5: Line 5:
This is a NSIS plug-in, that can call methods in your managed .NET DLL.
This is a NSIS plug-in, that can call methods in your managed .NET DLL.


You call your .NET DLL methods by specifying the DLL, the namespace in which your class exists, the class name and the method to be invoked. This is done using System::Call. You do not have to specify the parameter types, as the .NET DLL is scanned for parameters and their types. At the moment, the supported parameter types are string (unicode), int, float and boolean. Strings and floats must be enclosed in "". Return value can be of those types too.
Place the plugin in the NSIS plugins folder. You call your .NET DLL methods by calling CLR:Call. This expects the following parameters:
* Assembly dll filename
* Namespace and classname with dot in between
* Method name
* Number of parameters
* Parameters


Before calling the plug-in, call SetOutPath and copy both CLR.dll (this plug-in) and the .NET DLL to be invoked.
At the moment, the supported parameter types are string, char, int, float and boolean. Return value can be of those types too but are returned as strings to NSIS. Before calling the plug-in, call SetOutPath and copy the .NET DLL to be invoked.


Sample NSIS script calling a method in a .NET DLL, which takes four parameters: a string, int, float and a boolean and returns a string:
Sample NSIS script calling a method in a .NET DLL, which takes five parameters: string, char, int, float and boolean and returns a string:
<highlight-nsis>
<highlight-nsis>
InitPluginsDir
SetOutPath $PLUGINSDIR
SetOutPath $PLUGINSDIR
File "SomeAssembly.dll" ; some test .NET assembly
File "CLR.dll" ; this plugin
System::Call `CLR::Call(w 'SomeAssembly.dll::SomeNamespace::SomeClass::SomeMethod( \
  "some string value",12,"15.8",false)') w .r0`
</highlight-nsis>


While the plug-in is fully functional, it still undergoes some development and changes.
File "SomeAssembly.dll"
CLR::Call "SomeAssembly.dll" "SomeNamespace.SomeClass" \
  "SomeMethod" 5 "mystring1" "x" 10 15.8 false


== What I am working on ==
pop $0 
MessageBox MB_OK $0
</highlight-nsis>


* support for callbacks
The plug-in is fully functional but still undergoes some development and changes.
* a cleaner way of specifying method parameters
* both native NSIS plugin and plugin called via System::Call


== Download ==
== Download ==


Version 0.1 including source is available here <attach>CLR.zip</attach> as-is.
Version 0.2 including source is available here <attach>CLR.zip</attach> as-is.


[[Category:Plugins]]
[[Category:Plugins]]

Revision as of 00:32, 4 September 2008

Author: claesabrandt (talk, contrib)


NSIS forum thread

Description

This is a NSIS plug-in, that can call methods in your managed .NET DLL.

Place the plugin in the NSIS plugins folder. You call your .NET DLL methods by calling CLR:Call. This expects the following parameters:

  • Assembly dll filename
  • Namespace and classname with dot in between
  • Method name
  • Number of parameters
  • Parameters

At the moment, the supported parameter types are string, char, int, float and boolean. Return value can be of those types too but are returned as strings to NSIS. Before calling the plug-in, call SetOutPath and copy the .NET DLL to be invoked.

Sample NSIS script calling a method in a .NET DLL, which takes five parameters: string, char, int, float and boolean and returns a string:

InitPluginsDir
SetOutPath $PLUGINSDIR
 
File "SomeAssembly.dll"
CLR::Call "SomeAssembly.dll" "SomeNamespace.SomeClass" \
  "SomeMethod" 5 "mystring1" "x" 10 15.8 false
 
pop $0  
MessageBox MB_OK $0

The plug-in is fully functional but still undergoes some development and changes.

Download

Version 0.2 including source is available here CLR.zip (35 KB) as-is.