Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 24th June 2009, 08:20   #81
claesabrandt
Member
 
claesabrandt's Avatar
 
Join Date: Aug 2008
Location: Denmark
Posts: 54
SlyW: Sorry for the delay. I honestly don't know why .NET Framework SP1 makes things work, but your findings sound resonable.
claesabrandt is offline   Reply With Quote
Old 18th August 2009, 16:00   #82
dmccoy
Junior Member
 
Join Date: Aug 2009
Posts: 2
Dependency Assemblies

This may be old news, but I believe I have found a fix for the dependent assemblies problem using the AssemblyResolve event. I hope it will be of use to you.

My managed C++ skills are not the greatest, but please find attached my modified source file.

Thank you for creating the CLR NSIS plug in. It has proven very valuable - we use it often.

Best Regards,

David
Attached Files
File Type: txt nsis_clr_loader.txt (7.6 KB, 327 views)
dmccoy is offline   Reply With Quote
Old 19th August 2009, 06:45   #83
claesabrandt
Member
 
claesabrandt's Avatar
 
Join Date: Aug 2008
Location: Denmark
Posts: 54
Re: Dependency Assemblies

David, that looks interesting! That is really something I want to fix in the plugin. I will take a look at your code. I don't think this is old news, at least not for me, because I still had no solution to it. If I understand it right, will it then be possible to place the dependant assemblies anywhere and not necessarily in the same folder hierachy as the calling exe/dll?
claesabrandt is offline   Reply With Quote
Old 19th August 2009, 08:15   #84
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,338
What are the requirements for building this plug-in? Can I build it using VC6?

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 19th August 2009, 08:53   #85
claesabrandt
Member
 
claesabrandt's Avatar
 
Join Date: Aug 2008
Location: Denmark
Posts: 54
No. It has to be at least Visual Studio 2005 as .NET 2.0 must be supported.
claesabrandt is offline   Reply With Quote
Old 19th August 2009, 09:20   #86
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,338
Too bad... Will just have to wait for the day I finally switch to 2008 I guess. But keep 'em coming. It's a useful plug-in.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 19th August 2009, 09:50   #87
claesabrandt
Member
 
claesabrandt's Avatar
 
Join Date: Aug 2008
Location: Denmark
Posts: 54
The free express editions of VS works too, and can be installed alongside with VC6. Anyway, I will most likely implement Davids modification in the CLR.dll, so the dependant assembly problem will be solved for everyone, without having to recompile the source.
claesabrandt is offline   Reply With Quote
Old 19th August 2009, 15:15   #88
dmccoy
Junior Member
 
Join Date: Aug 2009
Posts: 2
Hi Claes,

The default assembly resolution mechanism should be called first, so assemblies registered in the GAC should still work. However, if the default assembly resolution fails it will attempt to load the assembly from the directory containing the assembly that was explicitly executed using CallCLR. I suppose it could be modified without a great deal of effort to accept a Java-like class path of directories to search for dependency assemblies.

Again, thank you for creating this plug in. We used it to replace a very clunky XML-driven solution that we used to use for performing install tasks from .NET DLLs.

Best Regards,

David
dmccoy is offline   Reply With Quote
Old 17th June 2010, 07:08   #89
timc_
Junior Member
 
Join Date: Jun 2010
Posts: 1
I notice it has been quite some time since talk of changing the way dependent assemblies are located. Is this no longer likely to happen?

Also, is there any particular reason why the plugin requires the assembly being called to have a .dll extension? I tried making calls to an exe (eg. foo.exe) and received a message indicating that the file (eg. foo.exe.dll) could not be found.
timc_ is offline   Reply With Quote
Old 27th September 2010, 17:21   #90
jayfox911
Junior Member
 
Join Date: Jun 2007
Location: san diego, ca
Posts: 13
Has anyone tested with Windows 7? I am trying to recompile my NSIS installer that was built on XP but now it will not work on Windows 7.
I have .NET 2.0 SP1 framework installed and download the newest CLR.zip form
http://nsis.sourceforge.net/Call_.NE...ethods_plug-in

nsi file
PHP Code:
OutFile "setup.exe"
Section

  InitPluginsDir
  SetOutPath $PLUGINSDIR
  
  File 
"AccessClass.dll"
  
File CLR.dll
  CLR
::Call /NOUNLOAD AccessClass.dll AccessClass.Access removeData 1 "dataTable"
  
  
pop $0  
  MessageBox MB_OK 
$0
  CLR
::Destroy
  
SectionEnd 
From the MakeNSISW
PHP Code:
InitPluginsDir
SetOutPath
"$PLUGINSDIR"
File"AccessClass.dll" ***91;compress***93; 4493/24576 bytes
File
"CLR.dll" ***91;compress***93; 31773/95744 bytes
Invalid command
CLR::Call
Error in script 
"C:\testscript.nsi" on line 9 -- aborting creation process 
jayfox911 is offline   Reply With Quote
Old 27th September 2010, 22:03   #91
jayfox911
Junior Member
 
Join Date: Jun 2007
Location: san diego, ca
Posts: 13
Quote:
Originally Posted by rbchasetfb View Post
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 Code:
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 IntPtrentry 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
                
SendMessageLV(hwndLVM_INSERTITEM0lv)
                
//Scroll the list so the item is visible
                
SendMessage(hwnd,LVM_SCROLL,0,12)
            Catch 
ex As Exception
                
Do Nothingjust return
            
End Try
        
End Sub

    End 
Class

End NameSpace 
NSIS Code with CLR.dll call to test with:
PHP Code:
Name "Test CLRDLL MakeLogEntry"
OutFile "TestCLRDLL.exe"
ShowInstDetails show
Var DetailsHWND
Page instfiles

Section
    DetailPrint 
"Starting Test"
    
InitPluginsDir
    SetOutPath $PLUGINSDIR
    File 
"TestCLRDLL.dll"
    
FindWindow $"#32770" "" $HWNDPARENT
    GetDlgItem $DetailsHWND 
$0 1016
    CLR
::Call "TestCLRDLL.dll" 
        "NSIS.TestClass" 
        "ChopString" 
        

        $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.
This example will not work for me also. Any ideas?
jayfox911 is offline   Reply With Quote
Old 28th September 2010, 19:41   #92
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,216
Firstly you don't need to extract plug-in DLL's to use them. NSIS handles that itself. Also, if NSIS says a plug-in call is an invalid command then that means your plug-in DLL isn't in the NSIS Plugins folder.

Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 28th September 2010, 20:42   #93
jayfox911
Junior Member
 
Join Date: Jun 2007
Location: san diego, ca
Posts: 13
Quote:
Originally Posted by Afrow UK View Post
Firstly you don't need to extract plug-in DLL's to use them. NSIS handles that itself. Also, if NSIS says a plug-in call is an invalid command then that means your plug-in DLL isn't in the NSIS Plugins folder.

Stu
Thank you that worked.
I put the CLR.dll in the \Program Files\NSIS\Plugins\ folder. Just like the second sentence of the CLR wiki says to do. Next time I will RTFM
jayfox911 is offline   Reply With Quote
Old 10th November 2010, 19:31   #94
taralex
Junior Member
 
Join Date: Nov 2010
Posts: 7
Unicode support

I got stuck for a couple of days when trying to move my installation to a Unicode-based NSIS. All my calls just stopped working. After a vain search for a similar dll, but supporting unicode, I downloaded the original source and upgraded it.
Now this was my first ever experience with c++, so I'm really not sure if I just didn't screw something up, but it worked in a couple of tests I did. I posted the link to the updated code on the Viki page.

I moved all the more or less complex functionality to a .net dll now, because all other means of calling dlls (like System::Call) stopped working in the Unicode release of NSIS.
taralex is offline   Reply With Quote
Old 19th September 2011, 17:22   #95
langdon
Junior Member
 
Join Date: May 2006
Posts: 15
Is anyone capable of recompiling this to add 4.0 support? It'll execute 4.0 assemblies, but will fail if you use any 3.5+ features (like simple Linq statements).
langdon is offline   Reply With Quote
Old 17th August 2012, 11:24   #96
mfiedlerwd
Junior Member
 
Join Date: Aug 2012
Posts: 2
Hi Claes,

I have already problems on setting/getting Properties.

Quote:
namespace test
{
public class test
{

// Properties
private string _Name = "";

public string Name
{
get { return _Name; }
set { _Name = value; }
}


public string helloworld()
{
return "Hello " + Name;
}
}
}
I first call the set_name Property, then the helloworld method. But allways the Propety is empty on the second call.

It seems that on every call will generated a new object instance of the dll.

Did you already hav fixed this problem? Or have a solution?

Best Regards,
Michael
mfiedlerwd is offline   Reply With Quote
Old 17th August 2012, 17:23   #97
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,216
To avoid incompatibility issues which can occur with different .NET versions I would put your .NET code into a command-line executable and run it using ExecDos.

Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 20th August 2012, 07:30   #98
mfiedlerwd
Junior Member
 
Join Date: Aug 2012
Posts: 2
Hi Stu, thanks for the suggestion.

Well, when i do a simple call it works fine with an exe or the dll as well.

But when i need to do multiple calls, i think i will have a problem with an exe. (ex. i have to do some database related work and in OLEDB-PLUGIN script files are limited to 60k, so i wrote a .net dll )

Best regards

Michael

Last edited by mfiedlerwd; 20th August 2012 at 09:36.
mfiedlerwd is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump