Call .NET DLL methods plug-in: Difference between revisions
Claesabrandt (talk | contribs) mNo edit summary |
|||
(8 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{PageAuthor|claesabrandt}} | {{PageAuthor|claesabrandt}} | ||
== Description == | == Description == | ||
Line 13: | Line 12: | ||
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. Note that the .NET class must be marked as public. | 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. Note that the .NET class must be marked as public. | ||
== Calling methods == | |||
Sample NSIS script calling a method in a .NET DLL, which takes five parameters: string, char, int, float and 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: | ||
Line 43: | Line 44: | ||
The plug-in is fully functional but still undergoes some development and changes. | The plug-in is fully functional but still undergoes some development and changes. | ||
== | == Calling properties == | ||
Currently you can call properties by using the get_ and set_ notation. If your property is called MyProperty, you can set it's value with set_MyProperty and you can get it's value with get_MyProperty. | |||
Example getting a property value: | |||
<highlight-nsis> | |||
CLR::Call /NOUNLOAD SomeAssembly.dll SomeNamespace.SomeClass get_MyProperty 0 | |||
pop $0 | |||
MessageBox MB_OK $0 | |||
</highlight-nsis> | |||
Example setting a property value: | |||
<highlight-nsis> | |||
CLR::Call /NOUNLOAD SomeAssembly.dll SomeNamespace.SomeClass set_MyProperty 1 "Hello Property" | |||
</highlight-nsis> | |||
Hello would you mind stating which blog pltfaorm you're working with? I'm planning to start my own blog soon but I'm having a difficult time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I'm looking for something completely unique. P.S My apologies for getting off-topic but I had to ask! | |||
== Download == | == Download == | ||
Version 0.5 including source is available here <attach>CLR.zip</attach> as-is. | Version 0.5 including source is available here <attach>CLR.zip</attach> as-is. | ||
Update: dll with Unicode support. [http://taralex.us/CLR.rar Link] | |||
== Prerequisites == | == Prerequisites == | ||
The plugin will need the .NET 2.0 framework to be installed on the target machine. It can be included in the installer or downloaded using for instance the inetc plugin. | The plugin will need the .NET 2.0 SP1 framework to be installed on the target machine. It can be included in the installer or downloaded using for instance the inetc plugin. | ||
== | == Known issues == | ||
When the installer finishes, the CLR.dll file remains in the temporary plugins directory on the target machine. The file is not locked, but somehow the plugin cannot be deleted. The next time the user reboots the machine, this file is deleted automatically. This issue is being worked on. | When the installer finishes, the CLR.dll file remains in the temporary plugins directory on the target machine. The file is not locked, but somehow the plugin cannot be deleted. The next time the user reboots the machine, this file is deleted automatically. This issue is being worked on. | ||
Another issue is that if want to call a .NET dll from your .NET dll, you will find that the installer cannot find the second .NET dll. For the moment the remedy is to wrap your installer in another installer. This other installer should place the .NET dlls in the same directory as the installer will run from. When the installer runs, the .NET dlls can now be found. There will only be distributed one setup file. | |||
== Version history == | == Version history == | ||
Line 66: | Line 85: | ||
* 0.4 CLR.dll is now compiled in release mode, in order to work on systems without VS2008 installed. Various other minor bugfixes as well. | * 0.4 CLR.dll is now compiled in release mode, in order to work on systems without VS2008 installed. Various other minor bugfixes as well. | ||
* 0.5 CLR.dll is now compiled with Visual Studio 2005 so there is no need for Visual C++ 2008 Redist. | * 0.5 CLR.dll is now compiled with Visual Studio 2005 so there is no need for Visual C++ 2008 Redist. | ||
* 2009-01-13: Added description of how to call properties. | |||
NSIS forum [http://forums.winamp.com/showthread.php?s=&threadid=295881 thread] | |||
[[Category:Plugins]] | [[Category:Plugins]] |
Latest revision as of 21:01, 15 May 2013
Author: claesabrandt (talk, contrib) |
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 (optional)
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. Note that the .NET class must be marked as public.
Calling methods
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 /NOUNLOAD "SomeAssembly.dll" "SomeNamespace.SomeClass" \ "SomeMethod" 5 "mystring1" "x" 10 15.8 false pop $0 MessageBox MB_OK $0 ... CLR::Destroy
Notice the /NOUNLOAD. This is nessecary if you need to call CLR::Call more than once, otherwise the installer hangs on the second call. When done with calling CLR::Call, call CLR::Destroy, for instance in .onGUIEnd.
You do not have to put quotes around the dll filename, namespace, classname and method, but if the dll filename contains spaces, you need the quotes around that. Omitting the quotes only makes the code slightly easier to read, the result is the same.
Sample NSIS script calling a .NET method that takes no parameters and returns void:
CLR::Call /NOUNLOAD SomeAssembly.dll SomeNamespace.SomeClass SomeOtherMethod 0 ... CLR::Destroy
The plug-in is fully functional but still undergoes some development and changes.
Calling properties
Currently you can call properties by using the get_ and set_ notation. If your property is called MyProperty, you can set it's value with set_MyProperty and you can get it's value with get_MyProperty.
Example getting a property value:
CLR::Call /NOUNLOAD SomeAssembly.dll SomeNamespace.SomeClass get_MyProperty 0 pop $0 MessageBox MB_OK $0
Example setting a property value:
CLR::Call /NOUNLOAD SomeAssembly.dll SomeNamespace.SomeClass set_MyProperty 1 "Hello Property"
Hello would you mind stating which blog pltfaorm you're working with? I'm planning to start my own blog soon but I'm having a difficult time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I'm looking for something completely unique. P.S My apologies for getting off-topic but I had to ask!
Download
Version 0.5 including source is available here CLR.zip (35 KB) as-is.
Update: dll with Unicode support. Link
Prerequisites
The plugin will need the .NET 2.0 SP1 framework to be installed on the target machine. It can be included in the installer or downloaded using for instance the inetc plugin.
Known issues
When the installer finishes, the CLR.dll file remains in the temporary plugins directory on the target machine. The file is not locked, but somehow the plugin cannot be deleted. The next time the user reboots the machine, this file is deleted automatically. This issue is being worked on.
Another issue is that if want to call a .NET dll from your .NET dll, you will find that the installer cannot find the second .NET dll. For the moment the remedy is to wrap your installer in another installer. This other installer should place the .NET dlls in the same directory as the installer will run from. When the installer runs, the .NET dlls can now be found. There will only be distributed one setup file.
Version history
- 0.1 Initial release of the plugin
- 0.2 Changed to native NSIS plugin and some bugfixes
- 0.3 Bugfix: If more than one class was found in an assembly, only the first one could be loaded.
- 0.4 CLR.dll is now compiled in release mode, in order to work on systems without VS2008 installed. Various other minor bugfixes as well.
- 0.5 CLR.dll is now compiled with Visual Studio 2005 so there is no need for Visual C++ 2008 Redist.
- 2009-01-13: Added description of how to call properties.
NSIS forum thread