WINAMP.COM | Forums > Developer Center > NSIS Discussion > Calling managed .NET DLL from NSIS - this works :-) |
| Pages (3): « 1 [2] 3 » |
Last Thread
Next Thread
|
| Author |
|
|
claesabrandt Member
Registered: Aug 2008 |
I finally found the problem! My CLR.dll must be compiled in release mode and the system onto which the installer is going to run must have the MS Visual C++ 2008 Redist package installed, which can be included in the installer. Last edited by claesabrandt on 09-09-2008 at 08:01 AM |
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
Just uploaded version 0.5 which is compiled with Visual Studio 2005, release mode. The need for MS Visual C++ 2008 Redist is now eliminated, in fact, it seems the 2005 redist is not needed either - just the .NET 2.0 framework. Thanks goes to rbchasetfb for great input. |
||
|
|
|
rbchasetfb Junior Member
Registered: Sep 2008 |
claesabrandt, very cool that we got through that one. Thanks for sticking with it too. As a thanks, I thought I would post some code that I use in my .NET dll that CLR.dll is calling. It allows the functions in the .NET dll to update the Details list during the install without have to wait to return to the installer and then do a DetailPrint call with some funky string work. The code is in VB.NET, but could easily be converted to C#. The error handling is a little brute force in the MakeLogEntry function, it just ignores the error and returns, potentially writing nothing to the Details list. Non-the-less, very useful I think. NSIS Code with CLR.dll call to test with:Lastly, I've attached a zip file of the TestCLRDLL.dll project for VS2005 and included the TESTCLRDLL.nsi as will. Enjoy. I hope it's as useful for use as it is for me.
|
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
Weeeeeee I cannot say how enthusiastic I am that you post this sample. I really need this too. Cool stuff. Thanks so much |
||
|
|
|
rbchasetfb Junior Member
Registered: Sep 2008 |
|
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
You can use my old wiki page on the subject. The code in it is not valid anymore, and the explanation on how to make the CLR.dll is outdated and users should look in the source code for the CLR.dll plugin instead. It is located here: http://nsis.sourceforge.net/Calling_Managed_.Net_DLL_From_NSIS |
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
If anyone needs to convert that VB.NET code to C#, here is a useful link: http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx. When converted some minor ajustments needs to be made. I guess I could post the C# version when I get home tonight. I will update the plugin wiki with this information. Last edited by claesabrandt on 09-11-2008 at 07:56 AM |
||
|
|
|
rbchasetfb Junior Member
Registered: Sep 2008 |
Thanks, claesabrandt, I'll get that page setup to on the wiki. I've also made the changes to the example. It is the way I'm using CLR.dll, just forgot to put it in the example. I've uploaded the new zip here until I get the wiki page done.
|
||
|
|
|
rbchasetfb Junior Member
Registered: Sep 2008 |
Wiki Page For DetailPrint from Inside .NET DLL
The wiki page for DetailPrint from Inside .NET DLL is finally up. I've posted some modified source code and some other things of value along with it, including the complete VS2005 project for the TestCLRDLL. |
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
Really nice article. I made a link to it from the plugin page. |
||
|
|
|
indimini Junior Member
Registered: Sep 2008 |
Clasesabrandt, thanks for putting this plugin together. It's turning into a life saver for me as I migrate from the Installer projects in VS 2008. |
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
If you need to perform some .NET call on uninstallation, I would keep a copy of the dll file in $INSTDIR, then when uninstalling I would copy that dll file to $PLUGINSDIR. |
||
|
|
|
rbchasetfb Junior Member
Registered: Sep 2008 |
Improved Tokenizer
claesabrandt, With the following code: Add the following include directive: Then add the code and header files from the attached zip file. Lastly, the only catch I found is that when passing file paths, they need to have double backslashes. I'm sure there's a fix in the c++ code somewhere, just haven't found it yet. So I just modified my NSIS macro that calls CLR::Call to do a string replace of single backslashes with double backslashes. Here's the CodeProject website that I found this tokenizer at. http://www.codeproject.com/KB/stl/tokenizer.aspx Enjoy.
|
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
Very nice code you found there. However I prefer the current method as it keeps the parameter list cleaner and easier to read. Having them inside a single string is harder to read. |
||
|
|
|
PeanutMocha Junior Member
Registered: Oct 2007 |
I'm trying to use this plugin for the first time and get an error message: with a line of code like this: and also tried this variant (unsure if I need to specify the number of parameters): What am I doing wrong? Thanks! |
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
You have to put the 1 before the parameter and it seems you are missing the namespace, should be something like this:
|
||
|
|
|
PeanutMocha Junior Member
Registered: Oct 2007 |
Thanks, putting the number of parameters first did the trick :-) |
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
Did you read the wiki here: http://nsis.sourceforge.net/Call_.NET_DLL_methods_plug-in. |
||
|
|
|
SlyW Junior Member
Registered: Apr 2004 |
Could not load ...\CLR.dll
I am running into a situation where I am unable to load the CLR.dll on 3 out of 5 machines. I have checked the .Net Framework versions and have concluded that although there are some discrepancies, at least two of the failing machines match the Framework version of one of the machine which does work. |
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
Hi SlyW. From your .NET dll, are you calling further into other .NET dlls? |
||
|
|
|
SlyW Junior Member
Registered: Apr 2004 |
None of my writing...
It is calling the System.Cryptography classes, but no other .NET DLLs of my creation.
|
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
SlyW, I am looking into it, but at the moment I am a bit clueless about it, as it sounds like NSIS can't load the plugin. I guess you don't have problems with other plugins on those machines? I am thinking of if you could try installing the Visual C++ 2005 redist on those machines. That should not be needed, but maybe you have found a scenario where it is needed. It is the CLR.dll it cannot find, right? Not your crypto dll. |
||
|
|
|
SlyW Junior Member
Registered: Apr 2004 |
I will try...
I will install the VC++ redist on one of the machines upon which the installer fails and let you know the progress. I would have done it already had I not been required to attend parent-teacher conferences. |
||
|
|
|
SlyW Junior Member
Registered: Apr 2004 |
No luck. Installed the VC++ 2005 Redist on one of the XP machines with the same results. Could not load CLR.dll and the value popped was the name of the encryption DLL. |
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
Thanks for the testing. This sounds like a problem rbchasetfb encountered back in the beginning of september. Back then we fixed it by making sure the DLL was compiled using Visual Studio 2005 and not 2008, as it seems it fixed it then. But I will have to look further into why NSIS fails to load the DLL in some cases. My first tasks is to reproduce the error myself. I might ask additional questions of you, to reproduce your scenario. |
||
|
|
|
SlyW Junior Member
Registered: Apr 2004 |
Ask away! And I will see if I can get VS.NET C++ installed locally. I might try installing VS.NET C++ on one of the machines where it fails and see if it helps. I know that VS.NET is installed on all three failing machines, however, only the VB.NET and Web Developer components are installed. |
||
|
|
|
teiles Junior Member
Registered: Oct 2008 |
My CLR.exe based DLL works on some machines and not others. |
||
|
|
|
rbchasetfb Junior Member
Registered: Sep 2008 |
I'll add some other successful test environments: |
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
rbchasetfb, very very good. SlyW, could you please try installing .NET 2.0 SP1 on the machines that fail? |
||
|
|
|
teiles Junior Member
Registered: Oct 2008 |
I just installed the .NET 2.0 SP1 on the Win 2003 .NET 2.0 that was failing. |
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
Great! Thanks for the excellent testing SlyW and teiles. rbchasetfb, you are my hero again |
||
|
|
|
SlyW Junior Member
Registered: Apr 2004 |
I will install SP1 on one or more of the failing machines and let you know the success/failure of each. |
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
Now that we are at the issues. I have encountered an annoying thing and have a workaround for it. If you call a second custom .NET DLL from your first custom .NET DLL, you will run into an issue about the .NET framework cannot find the second DLL, even if you have placed both DLLs in the $PLUGINSDIR. Your second DLL is referenced in your first DLLs Visual Studio project. |
||
|
|
|
SlyW Junior Member
Registered: Apr 2004 |
Success! I have successfully run the sample installer on a machine _after_ installing SP1. Now, to make SP1 a pre-req for installing our app. |
||
|
|
|
SlyW Junior Member
Registered: Apr 2004 |
Found additional error messages
I just happened to be perusing the Event Viewer on a machine where the CLR.dll failed to load and discovered the following three entries: |
||
|
|
|
AuGuS666 Junior Member
Registered: Jun 2008 |
Class Property
Hi and thx for watching this: And this is my nsis source: I did compilated my DllTest.dll on DEBUG, RELEASE, with Framework 2 SP1, i did try with VS Net 2005 and VS Net 2008 classes, Windows Xp SP3 Pc's and nothing yet (btw the get_ method works). Thx for replays
|
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
What error do you experience? |
||
|
|
|
AuGuS666 Junior Member
Registered: Jun 2008 |
Re: Class Property
I cant change the value of the property with the _setMyProperty method |
||
|
|
|
claesabrandt Member
Registered: Aug 2008 |
Sry for the delay. I have to look into this. I suspect it could have something to do with the internal variable not keeping the value between the calls. I am not sure how NSIS manages the memory when using NOUNLOAD on the calls. I thought the variables would keep their values. However, for now you must keep values in the NSIS script and pass them to the methods when needed. |
||
|
|
|
| Pages (3): « 1 [2] 3 » |
Last Thread Next Thread
|
WINAMP.COM | Forums > Developer Center > NSIS Discussion > Calling managed .NET DLL from NSIS - this works :-) |
Forum Rules:
|