WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 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
Thread Post New Thread    Post A Reply
claesabrandt
Member

Registered: Aug 2008
From: Denmark

Hmm, I now even tried compiling a C++ Win32 DLL without any .NET. This is only code from exdll.c and exdll.h. It does not run on the machine that my .NET plugin could not run on. Anyony any ideas?

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 09-08-2008 09:50 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

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.

I will release a new version of the zip file (v0.4). Could you test it for me rbchasetfb, so we can verify that the problem is fixed? If you want to use the 2005 edition of the redist, you can just compile the CLR.dll with VS2005 instead.

Would there be a greater wish for having it use the 2005 redist as default instead?

Last edited by claesabrandt on 09-09-2008 at 08:01 AM

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 09-09-2008 07:42 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

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.

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 09-09-2008 08:55 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
rbchasetfb
Junior Member

Registered: Sep 2008
From:

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.

VB.NET Code Required:

PHP:

Imports System
Imports System
.Runtime.InteropServices
Imports System
.Threading
Imports System
.IO
Imports System
.Windows.Forms

Namespace NSIS

    Public
Class TestClass

        
//LVITEM Structure Declaration.
        
<StructLayout(LayoutKind.Sequential)> _
        Public Structure LVITEM
            Public mask
As Int32
            Public iItem
As Int32
            Public iSubItem
As Int32
            Public state
As Int32
            Public stateMask
As Int32
            Public pszText
As String
            Public cchTextMax
As Int32
            Public iImage
As Int32
            Public lParam
As IntPtr
        End Structure

        
//SendMessage API declarations.
        
Public Declare Function SendMessageLV Lib "user32" Alias _
          
"SendMessageA"(ByVal hwnd As IntPtr, _
                         ByVal wMsg
As Int32, _
                         ByVal wParam
As Integer, _
                         ByRef lParam
As LVITEM) As Integer
        Public
Declare Function SendMessage Lib "user32" Alias _
          
"SendMessageA"(ByVal hwnd As IntPtr, _
                         ByVal wMsg
As Int32, _
                         ByVal wParam
As Integer, _
                         ByRef lParam
As Integer) As Integer                

        
//Constants used by LVITEM and SendMessage
        
Public Const LVM_FIRST as Integer = &H1000
        Public
Const LVM_GETITEMCOUNT as Integer = LVM_FIRST + 4
        Public
Const LVM_GETITEM as Integer = LVM_FIRST + 5
        Public
Const LVM_INSERTITEM as Integer = LVM_FIRST + 7
        Public
Const LVM_SCROLL as Integer = LVM_FIRST + 20
        Public
Const LVIF_TEXT as Integer = &H0001
        Public
Const LVIS_FOCUSED as Integer = &H0001

        
//Test function for calling from an NSIS installer using CLR.dll
        
Public Function ChopString( _
                ByVal hwnd
as IntPtr, _
                ByVal stringToChop
as String, _
                ByVal chopToLength
as Integer) As String
            Dim ret
as String = ""
            
If stringToChop.Length > chopToLength Then
                MakeLogEntry
(hwnd, "Chopping String '" & stringToChop & "'.")
                
ret = stringToChop.SubString(0,chopToLength)
                
MakeLogEntry(hwnd, "String chopped to '" & ret & "'.")
            Else
                
MakeLogEntry(hwnd, "String '" & _
                    stringToChop
& _
                    
"' to short to chop to length '" & _
                    chopToLength
& "'.")
            
End If
            Return
ret
        End
Function

        
//Here's the key function that writes to the Details list.
        
Public Sub MakeLogEntry(ByVal hwnd As IntPtr, entry as String)
            
Try
                
//Get current list count
                
Dim c as Integer = SendMessage(hwnd,LVM_GETITEMCOUNT,0,0)+1
                
//Setup a LVITEM structure for the Insert message
                
Dim lv As New LVITEM
                lv
.iItem = c
                lv
.pszText = entry
                lv
.mask = LVIF_TEXT
                lv
.stateMask = LVIS_FOCUSED
                lv
.state = LVIS_FOCUSED
                
//Insert the LVITEM into the list
                
c = SendMessageLV(hwnd, LVM_INSERTITEM, 0, lv)
                
//Scroll the list so the item is visible
                
SendMessage(hwnd,LVM_SCROLL,0,12)
            
Catch ex As Exception
                
'Do Nothing, just return
            End Try
        End Sub

    End Class

End NameSpace

NSIS Code with CLR.dll call to test with:
PHP:

Name
"Test CLRDLL MakeLogEntry"
OutFile "TestCLRDLL.exe"
ShowInstDetails show
Var DetailsHWND
Page instfiles

Section
    DetailPrint
"Starting Test"
    
InitPluginsDir
    SetOutPath $PLUGINSDIR
    File
"TestCLRDLL.dll"
    
FindWindow $0 "#32770" "" $HWNDPARENT
    GetDlgItem $DetailsHWND
$0 1016
    CLR
::Call "TestCLRDLL.dll"
        "NSIS.TestClass"
        "ChopString"
        
3
        $DetailsHWND
"Testing Make Log Entry" 9
    Pop
$0
    DetailPrint
"ChopString Result = $0"
    
DetailPrint "Test Complete"
SectionEnd


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.

Attachment: testclrdll.zip
This has been downloaded 192 time(s).

Quick Link | Report this post to a moderator | IP: Logged

rbchasetfb is offline Old Post 09-10-2008 07:22 PM
Click Here to See the Profile for rbchasetfb Find more posts by rbchasetfb Add rbchasetfb to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

Weeeeeee I cannot say how enthusiastic I am that you post this sample. I really need this too. Cool stuff. Thanks so much

You should make a nsis wiki sample page with this. Would be very beneficial.

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 09-10-2008 07:44 PM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
rbchasetfb
Junior Member

Registered: Sep 2008
From:

Glad you needed it...thought it would be handy. Will work on the wiki page over the next couple of days.

Quick Link | Report this post to a moderator | IP: Logged

rbchasetfb is offline Old Post 09-10-2008 07:57 PM
Click Here to See the Profile for rbchasetfb Find more posts by rbchasetfb Add rbchasetfb to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

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

You can just change the author and move the page to another name, that fits with your purpose. If you want I can make the initial posting for you. Or you can make a brand new page if you want to.

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 09-11-2008 06:28 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

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.

Btw rbchasetfb, I noticed in your sample that you call CLR::Call without /NOUNLOAD. I found that if you attempt to call CLR:Call again after that, the installer hangs. You must specify the /NOUNLOAD each time. Then when done, call CLR:: Destroy, for instance in .onGUIEnd (without the space but smileys are attacking me). For instance:

PHP:

CLR
::Call /NOUNLOAD parameters...
CLR:: Destroy


I will update the plugin wiki with this information.

Last edited by claesabrandt on 09-11-2008 at 07:56 AM

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 09-11-2008 07:31 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
rbchasetfb
Junior Member

Registered: Sep 2008
From:

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.

Attachment: testclrdll.zip
This has been downloaded 186 time(s).

Quick Link | Report this post to a moderator | IP: Logged

rbchasetfb is offline Old Post 09-11-2008 02:36 PM
Click Here to See the Profile for rbchasetfb Find more posts by rbchasetfb Add rbchasetfb to your buddy list Edit/Delete Message Reply w/Quote
rbchasetfb
Junior Member

Registered: Sep 2008
From:

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.

http://nsis.sourceforge.net/DetailPrint_From_Inside_.NET_DLL

claesabrandt, maybe you can put a link to it on your NSIS wiki page as I've posted it to the Code Examples category since it's not really a plugin.

Enjoy.

Quick Link | Report this post to a moderator | IP: Logged

rbchasetfb is offline Old Post 09-12-2008 02:21 PM
Click Here to See the Profile for rbchasetfb Find more posts by rbchasetfb Add rbchasetfb to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

Really nice article. I made a link to it from the plugin page.

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 09-13-2008 12:45 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
indimini
Junior Member

Registered: Sep 2008
From:

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.

I've got my install actions from my VS 2008 installer ported over to use your plugin, but I'm stuck trying to figure out how to run a .NET method during uninstall. It seems like the DLL file used during installation is not available. Any thoughts or suggestions?

Quick Link | Report this post to a moderator | IP: Logged

indimini is offline Old Post 09-19-2008 09:49 PM
Click Here to See the Profile for indimini Click here to Send indimini a Private Message Click Here to Email indimini Find more posts by indimini Add indimini to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

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.

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 09-20-2008 12:16 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
rbchasetfb
Junior Member

Registered: Sep 2008
From:

Improved Tokenizer

claesabrandt,

I found a solution to the need for passing the parameter count. When we talked before, I had implemented a parameter parser that didn't take into account commas in string parameters, well, I found the fix for that. Found a string tokenizer code module that allows you to spec the delimiters, constraining quotes that will cause delimiter to be ignored and a couple other cool options. To use this, replace the following code in NSIS_CLR_Loader.cpp:

PHP:

// num params
    
popstring(buf);
    
int numparams = atoi(buf);

    
// params
    
vector<string> args;
    for (
int i=0; i<numparams; i++)
    {
        
popstring(buf);
        
string tmp = string(buf);
        
args.push_back(tmp);
    }


With the following code:
PHP:

// params
    
popstring(buf);
    
string sargs = string(buf);
    
vector<string> args;
    
    
tokenize (sargs,args,",","","\'","\\");


Add the following include directive:
PHP:

#include "tokenizer.h"


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.

Attachment: tokenizer code.zip
This has been downloaded 149 time(s).

Quick Link | Report this post to a moderator | IP: Logged

rbchasetfb is offline Old Post 09-24-2008 04:27 PM
Click Here to See the Profile for rbchasetfb Find more posts by rbchasetfb Add rbchasetfb to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

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.

What do you think? Is it better to have all parameters in one string, or is it better to have them seperated?

Actually, I could just make an additional function with the tokenizer, so people can choose themselves Should I do that?

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 09-25-2008 09:47 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
PeanutMocha
Junior Member

Registered: Oct 2007
From:

I'm trying to use this plugin for the first time and get an error message:

Error calling .NET DLL method
Number of parameters does not match

I'm trying to call my C# method:

PHP:

public
static bool LogTest(string eventSource)



with a line of code like this:

PHP:

CLR
::Call /NOUNLOAD Util.dll Util LogTest "Sample"



and also tried this variant (unsure if I need to specify the number of parameters):

PHP:

CLR
::Call /NOUNLOAD Util.dll Util LogTest "Sample" 1



What am I doing wrong?

Thanks!

Quick Link | Report this post to a moderator | IP: Logged

PeanutMocha is offline Old Post 10-27-2008 07:27 AM
Click Here to See the Profile for PeanutMocha Click here to Send PeanutMocha a Private Message Find more posts by PeanutMocha Add PeanutMocha to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

You have to put the 1 before the parameter and it seems you are missing the namespace, should be something like this:

PHP:

CLR
::Call /NOUNLOAD Util.dll SomeNamespace.Util LogTest 1 "Sample"

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 10-27-2008 07:42 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
PeanutMocha
Junior Member

Registered: Oct 2007
From:

Thanks, putting the number of parameters first did the trick :-)

It might be worth updating the Wiki a bit to make the parameter passing scheme clearer. Reading through this thread, there have been a few iterations on how to pass parameters so something in the Wiki like:

CLR::Call /NOUNLOAD MyModule.dll My.Name.Space MyMethod [NumberOfParameters] [Parameter List]

Where [NumberOfParameters] is the integer number of parameters present

[Parameter List] is a list of string, float or integer parameters separated by space. String parameters must be enclosed in quotes.

Would make things a bit clearer to those new to NSIS and this plugin.

Quick Link | Report this post to a moderator | IP: Logged

PeanutMocha is offline Old Post 10-27-2008 03:50 PM
Click Here to See the Profile for PeanutMocha Click here to Send PeanutMocha a Private Message Find more posts by PeanutMocha Add PeanutMocha to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

Did you read the wiki here: http://nsis.sourceforge.net/Call_.NET_DLL_methods_plug-in.

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 10-27-2008 04:45 PM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
SlyW
Junior Member

Registered: Apr 2004
From:

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.

Is there an enhanced logging mechanism I can invoke to obtain more information relating to the inability to load the library?

When it works, I am in love with plugin. Thank you VERY much!

- SlyW

P.S. If you want my .nsi and .Net DLL, please ask.

Quick Link | Report this post to a moderator | IP: Logged

SlyW is offline Old Post 10-28-2008 07:06 PM
Click Here to See the Profile for SlyW Click here to Send SlyW a Private Message Find more posts by SlyW Add SlyW to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

Hi SlyW. From your .NET dll, are you calling further into other .NET dlls?

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 10-28-2008 07:59 PM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
SlyW
Junior Member

Registered: Apr 2004
From:

None of my writing...

It is calling the System.Cryptography classes, but no other .NET DLLs of my creation.

I have attached complete source code to this message including the source of my encryption library.

Thanks!

-SlyW

Attachment: nsis_source.zip
This has been downloaded 153 time(s).

Quick Link | Report this post to a moderator | IP: Logged

SlyW is offline Old Post 10-28-2008 08:29 PM
Click Here to See the Profile for SlyW Click here to Send SlyW a Private Message Find more posts by SlyW Add SlyW to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

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.

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 10-28-2008 09:43 PM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
SlyW
Junior Member

Registered: Apr 2004
From:

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.

Thanks for your excellent responses so far!

Quick Link | Report this post to a moderator | IP: Logged

SlyW is offline Old Post 10-29-2008 04:07 AM
Click Here to See the Profile for SlyW Click here to Send SlyW a Private Message Find more posts by SlyW Add SlyW to your buddy list Edit/Delete Message Reply w/Quote
SlyW
Junior Member

Registered: Apr 2004
From:

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.

Quick Link | Report this post to a moderator | IP: Logged

SlyW is offline Old Post 10-29-2008 05:30 PM
Click Here to See the Profile for SlyW Click here to Send SlyW a Private Message Find more posts by SlyW Add SlyW to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

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.

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 10-30-2008 11:28 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
SlyW
Junior Member

Registered: Apr 2004
From:

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.

If there are debug flags you want me to use, please do not hesitate to ask.

Quick Link | Report this post to a moderator | IP: Logged

SlyW is offline Old Post 10-30-2008 01:46 PM
Click Here to See the Profile for SlyW Click here to Send SlyW a Private Message Find more posts by SlyW Add SlyW to your buddy list Edit/Delete Message Reply w/Quote
teiles
Junior Member

Registered: Oct 2008
From:

My CLR.exe based DLL works on some machines and not others.

What I know:

Win XP SP2 w/.NET 2/3/3.5 works
Vista SP1 w/.NET 2/3/3.5 works
Win 2003 w/.NET 2/3/3.5 works
Win 2003 w/.NET 2 DOES NOT WORK

Quick Link | Report this post to a moderator | IP: Logged

teiles is offline Old Post 10-30-2008 09:43 PM
Click Here to See the Profile for teiles Click here to Send teiles a Private Message Find more posts by teiles Add teiles to your buddy list Edit/Delete Message Reply w/Quote
rbchasetfb
Junior Member

Registered: Sep 2008
From:

I'll add some other successful test environments:

Win 2003 w/SP1 or SP2 and a minimum of .NET 2.0 SP1
Win XP SP2 with a minimum of .NET 2.0 SP1

The catch is the SP1 version of .NET 2.0. The CLR plugin on DotNET 2.0 without SP1 will not work on any of these environments. The reason your .NET 2/3/3.5 works is the .NET 3 and 3.5 installers install the .NET 2.0 SP1 patches. claesabrandt, that's why the VS2005 compiled CLR only works on this .NET 2.0 SP1 setup...because you have installed .NET 3 and/3.5.

To overcome this, I've added a prerequisites custom page to my installers, right after my license page, that checks for and downloads, installs/upgrades .NET 2.0 SP1 before any calls to the CLR plugin. I use the CLR plugin in custom pages after the components selection page. If this sequence doesn't work for you, you can put a .NET check-download-and-install into the .onInit. A recommended .onInit would do some conformance checks anyway, so here's a good order:

1. Check if installer is already running, if so abort
2. Check for local admin rights, if not, abort
3. Check for and Install IIS (if installing a web site on IIS)
4. Check for and Install .NET 2.0 SP1

It took me some time to figure this one out - and lots of VirtualMachine undo drive wipes - so I hope this saves you all some time.

Quick Link | Report this post to a moderator | IP: Logged

rbchasetfb is offline Old Post 10-31-2008 01:40 PM
Click Here to See the Profile for rbchasetfb Find more posts by rbchasetfb Add rbchasetfb to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

rbchasetfb, very very good. SlyW, could you please try installing .NET 2.0 SP1 on the machines that fail?

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 10-31-2008 02:08 PM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
teiles
Junior Member

Registered: Oct 2008
From:

I just installed the .NET 2.0 SP1 on the Win 2003 .NET 2.0 that was failing.

CLR.exe now WORKS!!!

Thanks --- Ted

Quick Link | Report this post to a moderator | IP: Logged

teiles is offline Old Post 10-31-2008 03:50 PM
Click Here to See the Profile for teiles Click here to Send teiles a Private Message Find more posts by teiles Add teiles to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

Great! Thanks for the excellent testing SlyW and teiles. rbchasetfb, you are my hero again I have updated the wiki with the SP1 prerequisite. I assume that this is the solution to the problem. Let me know if not.

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 10-31-2008 05:39 PM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
SlyW
Junior Member

Registered: Apr 2004
From:

I will install SP1 on one or more of the failing machines and let you know the success/failure of each.

Thank you _all_ for making this a useful forum and an even more useful plugin!

Quick Link | Report this post to a moderator | IP: Logged

SlyW is offline Old Post 11-01-2008 07:12 PM
Click Here to See the Profile for SlyW Click here to Send SlyW a Private Message Find more posts by SlyW Add SlyW to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

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.

The reason the second DLL cannot be found is that .NET looks for the DLL in the same directory as the calling process, which in this is case is the installer exe. You can make .NET look in a subdirectory of the calling process, but here comes the issue. Your installer will run from some location, and then it unpacks everything into a temp directory. From that directory it loads the first DLL by loading it into memory and then using reflection to scan the methods and properties, so the process does not have to look for the DLL. The second DLL is not loaded this way as it is referenced from the first DLL's project. Here I rely on that the .NET framework can find it, and as it was not unpacked in the installer's directory or subdirectory, I have not found a way to make .NET find it.

My workaround has been to make a second NSIS script that wraps my installer script and wraps the .NET DLLs needed in my installer script. These are unpacked to the temp directory together and when the second script is executed using Exec, the second installer will be the executing process and thus it can find the DLLs. When the second installer finishes, I delete the files again.

Although this works, it would be nice to have a "real" solution, where the .NET framework can actually find the second DLL. I have tried all kinds of things, googled for it etc. I have not yet found a solution to make .NET look for a DLL in another directory other than where the calling process is run from or subdirectories of that. If anyone have ideas, let's see if we can find a better solution.

A note: One should not unpack the DLLs in the same directory as the installer, as the installer might be run from a CD-Rom or other readonly media.

A second note: One could use reflection, like how the first DLL is loaded, to load the second DLL. But this as two drawbacks: 1) Using reflection, there will be a weak binding between your DLLs and you will not have code completion in your project when trying to call things in the second DLL. 2) You would have to use reflection again if trying to call a third or fourth DLL.

Regards Claes

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 11-06-2008 07:46 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
SlyW
Junior Member

Registered: Apr 2004
From:

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.

Thanks again for all your help (to everyone)!

BTW: Do we dare ask what SP1 brings to the table that suddenly enables this functionality?

Quick Link | Report this post to a moderator | IP: Logged

SlyW is offline Old Post 11-10-2008 03:54 AM
Click Here to See the Profile for SlyW Click here to Send SlyW a Private Message Find more posts by SlyW Add SlyW to your buddy list Edit/Delete Message Reply w/Quote
SlyW
Junior Member

Registered: Apr 2004
From:

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:

Dependent Assembly Microsoft.VC80.CRT could not be found and Last Error was The referenced assembly is not installed on your system.

Resolve Partial Assembly failed for Microsoft.VC80.CRT. Reference error message: The referenced assembly is not installed on your system.

Generate Activation Context failed for C:\DOCUME~1\USERSL~1\LOCALS~1\Temp\nsy57D.tmp\CLR.dll. Reference error message: The operation completed successfully.

So, apparently SP1 somehow brings Microsoft.VB80.CRT into the fold?

Quick Link | Report this post to a moderator | IP: Logged

SlyW is offline Old Post 11-17-2008 04:34 PM
Click Here to See the Profile for SlyW Click here to Send SlyW a Private Message Find more posts by SlyW Add SlyW to your buddy list Edit/Delete Message Reply w/Quote
AuGuS666
Junior Member

Registered: Jun 2008
From:

Class Property

Hi and thx for watching this:

Calling the method "SayHi" from my c# dll works fine, but the set_MyProperty method to setting the public property "name" dont work for me, here is my simple C# class:

PHP:

using System
;
using System.Collections.Generic;
using System.Text;

namespace DllTest{

    
public class greeting{

      
private string m_strname;

      
public greeting() {
      }

      
public string SayHi(){
        return
"hi " + name;

      }

        
public string name{
            
get { return m_strname; }
            
set { m_strname = value; }
        }
    }
}



And this is my nsis source:

PHP:

Section
SetOutPath $PLUGINSDIR
File
"DllTest.dll"
        
CLR::Call /NOUNLOAD DllTest.dll DllTest.greeting set_name 1 "augus666"
        
CLR::Call /NOUNLOAD DllTest.dll DllTest.greeting SayHi 0
        pop
$0
        detailprint
$0
        CLR
:: Destroy

SectionEnd



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

Quick Link | Report this post to a moderator | IP: Logged

AuGuS666 is offline Old Post 03-28-2009 05:54 AM
Click Here to See the Profile for AuGuS666 Click here to Send AuGuS666 a Private Message Click Here to Email AuGuS666 Find more posts by AuGuS666 Add AuGuS666 to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

What error do you experience?

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 03-28-2009 06:24 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
AuGuS666
Junior Member

Registered: Jun 2008
From:

Re: Class Property

I cant change the value of the property with the _setMyProperty method

Quick Link | Report this post to a moderator | IP: Logged

AuGuS666 is offline Old Post 03-28-2009 03:56 PM
Click Here to See the Profile for AuGuS666 Click here to Send AuGuS666 a Private Message Click Here to Email AuGuS666 Find more posts by AuGuS666 Add AuGuS666 to your buddy list Edit/Delete Message Reply w/Quote
claesabrandt
Member

Registered: Aug 2008
From: Denmark

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.

Quick Link | Report this post to a moderator | IP: Logged

claesabrandt is offline Old Post 06-24-2009 08:11 AM
Click Here to See the Profile for claesabrandt Click here to Send claesabrandt a Private Message Find more posts by claesabrandt Add claesabrandt to your buddy list Edit/Delete Message Reply w/Quote
All times are GMT. The time now is 08:29 PM. Post New Thread    Post A Reply
Pages (3): « 1 [2] 3 »   Last Thread   Next Thread
WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > Calling managed .NET DLL from NSIS - this works :-)
Show Printable Version
 | 
Email this Page
 | 
Subscribe to this Thread

Forum Jump:
 

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is off
vB code is ON
Smilies are ON
[IMG] code is ON