<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://nsis.sourceforge.io/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=VisualCSharp</id>
	<title>NSIS Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://nsis.sourceforge.io/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=VisualCSharp"/>
	<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/Special:Contributions/VisualCSharp"/>
	<updated>2026-04-21T22:40:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=DetailPrint_From_Inside_.NET_DLL&amp;diff=16128</id>
		<title>DetailPrint From Inside .NET DLL</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=DetailPrint_From_Inside_.NET_DLL&amp;diff=16128"/>
		<updated>2008-09-13T04:10:59Z</updated>

		<summary type="html">&lt;p&gt;VisualCSharp: Added DetailPrint code for C#&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{PageAuthor|rbchasetfb}}&lt;br /&gt;
== Description ==&lt;br /&gt;
If your using the [[Call .NET DLL methods plug-in]] to call .NET DLL functions to perform work during an install, one of the things that will be useful is to be able to update the Details list in the installer, from the DLL, while a .NET DLL function call is executing. Below is some VB.NET code, easily converted to C# at [http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx DEVELOPERfusion], that provides a method &#039;&#039;&#039;DetailPrint&#039;&#039;&#039; that adds an &#039;&#039;entry&#039;&#039; to the end of the Details list.&lt;br /&gt;
&lt;br /&gt;
The VB.NET source code is for a complete namespace and class and includes an example function &#039;&#039;&#039;ChopString&#039;&#039;&#039; to test with. You&#039;ll also find an NSIS test script. Lastly, a zip file is attached with the complete Visual Studio 2005 project for the test .NET DLL and the NSIS test script. Also included in the zip is &#039;&#039;ListViewDeclarations.vb&#039;&#039; that has all the declarations necessary for working with List-view controls from VB.NET. This file also has the &#039;&#039;&#039;DetailPrint&#039;&#039;&#039; method...all this is contained in a VB.NET &amp;lt;font style=&amp;quot;color:blue&amp;quot;&amp;gt;#Region&amp;lt;/font&amp;gt; you can drop in your .NET DLL.&lt;br /&gt;
&lt;br /&gt;
== VB.NET Source Code ==&lt;br /&gt;
&amp;lt;highlight-vbnet&amp;gt;&lt;br /&gt;
Imports System&lt;br /&gt;
Imports System.Runtime.InteropServices&lt;br /&gt;
&lt;br /&gt;
Namespace NSIS&lt;br /&gt;
   Public Class TestClass&lt;br /&gt;
      &#039;The LVITEM stucture specifies or receives the attributes of a list-view item.&lt;br /&gt;
      &amp;lt;StructLayout(LayoutKind.Sequential)&amp;gt; _&lt;br /&gt;
      Public Structure LVITEM&lt;br /&gt;
         Public mask As Int32&lt;br /&gt;
         Public iItem As Int32&lt;br /&gt;
         Public iSubItem As Int32&lt;br /&gt;
         Public state As Int32&lt;br /&gt;
         Public stateMask As Int32&lt;br /&gt;
         Public pszText As String&lt;br /&gt;
         Public cchTextMax As Int32&lt;br /&gt;
         Public iImage As Int32&lt;br /&gt;
         Public lParam As IntPtr&lt;br /&gt;
      End Structure&lt;br /&gt;
&lt;br /&gt;
      &#039;SendMessage API declarations. Two different declarations to manage two lparam types.&lt;br /&gt;
      Public Declare Function SendMessageLV Lib &amp;quot;user32&amp;quot; Alias _&lt;br /&gt;
         &amp;quot;SendMessageA&amp;quot;(ByVal hwnd As IntPtr, _&lt;br /&gt;
                        ByVal wMsg As Int32, _&lt;br /&gt;
                        ByVal wParam As Integer, _&lt;br /&gt;
                        ByRef lParam As LVITEM) As Integer&lt;br /&gt;
      Public Declare Function SendMessage Lib &amp;quot;user32&amp;quot; Alias _&lt;br /&gt;
         &amp;quot;SendMessageA&amp;quot;(ByVal hwnd As IntPtr, _&lt;br /&gt;
                        ByVal wMsg As Int32, _&lt;br /&gt;
                        ByVal wParam As Integer, _&lt;br /&gt;
                        ByRef lParam As Integer) As Integer&lt;br /&gt;
&lt;br /&gt;
      &#039;Constants used by LVITEM and SendMessage &lt;br /&gt;
      Public Const LVM_FIRST as Integer = &amp;amp;H1000 &lt;br /&gt;
      Public Const LVM_GETITEMCOUNT as Integer = LVM_FIRST + 4&lt;br /&gt;
      Public Const LVM_GETITEM as Integer = LVM_FIRST + 5&lt;br /&gt;
      Public Const LVM_INSERTITEM as Integer = LVM_FIRST + 7&lt;br /&gt;
      Public Const LVM_SCROLL as Integer = LVM_FIRST + 20&lt;br /&gt;
      Public Const LVIF_TEXT as Integer = &amp;amp;H0001&lt;br /&gt;
      Public Const LVIS_FOCUSED as Integer = &amp;amp;H0001&lt;br /&gt;
&lt;br /&gt;
      &#039;Here&#039;s the key function that writes to the Details list.&lt;br /&gt;
      Public Sub DetailPrint(ByVal hwnd As IntPtr, entry as String)&lt;br /&gt;
         Try&lt;br /&gt;
            &#039;Get current list count&lt;br /&gt;
            Dim c as Integer = SendMessage(hwnd,LVM_GETITEMCOUNT,0,0)+1&lt;br /&gt;
            &#039;Setup a LVITEM structure for the Insert message&lt;br /&gt;
            Dim lv As New LVITEM&lt;br /&gt;
            lv.iItem = c&lt;br /&gt;
            lv.pszText = entry&lt;br /&gt;
            lv.mask = LVIF_TEXT&lt;br /&gt;
            lv.stateMask = LVIS_FOCUSED&lt;br /&gt;
            lv.state = LVIS_FOCUSED&lt;br /&gt;
            &#039;Insert the LVITEM into the list&lt;br /&gt;
            c = SendMessageLV(hwnd, LVM_INSERTITEM, 0, lv)&lt;br /&gt;
            &#039;Scroll the list so the item is visible&lt;br /&gt;
            SendMessage(hwnd,LVM_SCROLL,0,12)&lt;br /&gt;
         Catch ex As Exception&lt;br /&gt;
            &#039;Do Nothing, no sense throwing an error just for logging.&lt;br /&gt;
         End Try&lt;br /&gt;
      End Sub&lt;br /&gt;
&lt;br /&gt;
      &#039;Test function for calling from an NSIS installer using CLR.dll&lt;br /&gt;
      Public Function ChopString(ByVal hwnd as IntPtr, ByVal stringToChop as String, _&lt;br /&gt;
                                 ByVal chopToLength as Integer) As String&lt;br /&gt;
         Dim ret as String = &amp;quot;&amp;quot;&lt;br /&gt;
         If stringToChop.Length &amp;gt; chopToLength Then&lt;br /&gt;
            DetailPrint(hwnd, &amp;quot;FROM DLL: Chopping String &#039;&amp;quot; &amp;amp; stringToChop &amp;amp; &amp;quot;&#039;&amp;quot;)&lt;br /&gt;
            ret = stringToChop.SubString(0,chopToLength)&lt;br /&gt;
            DetailPrint(hwnd, &amp;quot;FROM DLL: String chopped to &#039;&amp;quot; &amp;amp; ret &amp;amp; &amp;quot;&#039;&amp;quot;)&lt;br /&gt;
         Else&lt;br /&gt;
            DetailPrint(hwnd, &amp;quot;FROM DLL: String &#039;&amp;quot; &amp;amp; stringToChop &amp;amp; _&lt;br /&gt;
            &amp;quot;&#039; insufficient length to chop to &amp;quot; &amp;amp; chopToLength &amp;amp; &amp;quot; characters&amp;quot;)&lt;br /&gt;
            ret = &amp;quot;error&amp;quot;&lt;br /&gt;
         End If&lt;br /&gt;
         Return ret&lt;br /&gt;
      End Function&lt;br /&gt;
   End Class&lt;br /&gt;
End NameSpace&lt;br /&gt;
&amp;lt;/highlight-vbnet&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DetailPrint C# Source Code ==&lt;br /&gt;
&lt;br /&gt;
This code uses C# 3.0 object initializers, which for earlier versions of C# should be changed to standard property initializations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-csharp&amp;gt;&lt;br /&gt;
public static class NSIS&lt;br /&gt;
{&lt;br /&gt;
	private const int LVIF_TEXT = 0x1;&lt;br /&gt;
	private const int LVIS_FOCUSED = 0x1;&lt;br /&gt;
	private const int LVM_FIRST = 0x1000;&lt;br /&gt;
	private const int LVM_GETITEMCOUNT = LVM_FIRST + 4;&lt;br /&gt;
	private const int LVM_INSERTITEM = LVM_FIRST + 7;&lt;br /&gt;
	private const int LVM_SCROLL = LVM_FIRST + 20;&lt;br /&gt;
&lt;br /&gt;
	[DllImport(&amp;quot;user32.dll&amp;quot;)]&lt;br /&gt;
	private static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);&lt;br /&gt;
&lt;br /&gt;
	[DllImport(&amp;quot;user32.dll&amp;quot;)]&lt;br /&gt;
	private static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, ref LVITEM lParam);&lt;br /&gt;
&lt;br /&gt;
	public static void DetailPrint(IntPtr hWndDetail, string entry)&lt;br /&gt;
	{&lt;br /&gt;
		try&lt;br /&gt;
		{&lt;br /&gt;
			int c = SendMessage(hWndDetail, LVM_GETITEMCOUNT, 0, 0) + 1;&lt;br /&gt;
			var lvitem = new LVITEM&lt;br /&gt;
			             	{&lt;br /&gt;
			             		iItem = c,&lt;br /&gt;
			             		pszText = entry,&lt;br /&gt;
			             		mask = LVIF_TEXT,&lt;br /&gt;
			             		stateMask = LVIS_FOCUSED,&lt;br /&gt;
			             		state = LVIS_FOCUSED&lt;br /&gt;
			             	};&lt;br /&gt;
&lt;br /&gt;
			SendMessage(hWndDetail, LVM_INSERTITEM, 0, ref lvitem);&lt;br /&gt;
			SendMessage(hWndDetail, LVM_SCROLL, 0, 12);&lt;br /&gt;
		}&lt;br /&gt;
		catch&lt;br /&gt;
		{&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	#region Nested type: LVITEM&lt;br /&gt;
&lt;br /&gt;
	[StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
	public struct LVITEM&lt;br /&gt;
	{&lt;br /&gt;
		public int mask;&lt;br /&gt;
		public int iItem;&lt;br /&gt;
		public int iSubItem;&lt;br /&gt;
		public int state;&lt;br /&gt;
		public int stateMask;&lt;br /&gt;
		public string pszText;&lt;br /&gt;
		public int cchTextMax;&lt;br /&gt;
		public int iImage;&lt;br /&gt;
		public IntPtr lParam;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	#endregion&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/highlight-csharp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== NSIS Test Script ==&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
Name &amp;quot;Test CLRDLL MakeLogEntry&amp;quot;&lt;br /&gt;
OutFile &amp;quot;TestCLRDLL.exe&amp;quot;&lt;br /&gt;
ShowInstDetails show&lt;br /&gt;
Var DetailsHWND&lt;br /&gt;
Page instfiles&lt;br /&gt;
&lt;br /&gt;
Function .onGUIEnd&lt;br /&gt;
   CLR::Destroy&lt;br /&gt;
FunctionEnd&lt;br /&gt;
&lt;br /&gt;
Section&lt;br /&gt;
   InitPluginsDir&lt;br /&gt;
   SetOutPath $PLUGINSDIR&lt;br /&gt;
   File &amp;quot;TestCLRDLL.dll&amp;quot;&lt;br /&gt;
   DetailPrint &amp;quot;====================================&amp;quot;&lt;br /&gt;
   FindWindow $0 &amp;quot;#32770&amp;quot; &amp;quot;&amp;quot; $HWNDPARENT&lt;br /&gt;
   GetDlgItem $DetailsHWND $0 1016&lt;br /&gt;
   CLR::Call /NOUNLOAD &amp;quot;TestCLRDLL.dll&amp;quot; \&lt;br /&gt;
      &amp;quot;NSIS.TestClass&amp;quot; \&lt;br /&gt;
      &amp;quot;ChopString&amp;quot; \&lt;br /&gt;
      3 \&lt;br /&gt;
      $DetailsHWND &amp;quot;Testing Make Log Entry&amp;quot; 9&lt;br /&gt;
   Pop $0&lt;br /&gt;
   DetailPrint &amp;quot;ChopString Result = $0&amp;quot;&lt;br /&gt;
   DetailPrint &amp;quot;====================================&amp;quot;&lt;br /&gt;
   DetailPrint &amp;quot;Chopping a short string to gen error&amp;quot;&lt;br /&gt;
      CLR::Call /NOUNLOAD &amp;quot;TestCLRDLL.dll&amp;quot; \&lt;br /&gt;
      &amp;quot;NSIS.TestClass&amp;quot; \&lt;br /&gt;
      &amp;quot;ChopString&amp;quot; \&lt;br /&gt;
      3 \&lt;br /&gt;
      $DetailsHWND &amp;quot;Testing&amp;quot; 9&lt;br /&gt;
   Pop $0&lt;br /&gt;
   DetailPrint &amp;quot;ChopString Result = $0&amp;quot;&lt;br /&gt;
SectionEnd&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
You&#039;ll need to have the CLR.dll in your NSIS plugins directory. You can get it from the [[Call .NET DLL methods plug-in]] page or here &amp;lt;attach&amp;gt;CLR.zip&amp;lt;/attach&amp;gt; &#039;&#039;(As Is)&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
== Download ==&lt;br /&gt;
Here&#039;s the latest version of this little package including the Visual Studio 2005 project, NSIS Test Script and &#039;&#039;ListViewDeclarations.vb&#039;&#039; file. &amp;lt;attach&amp;gt;TestCLRDLL.zip&amp;lt;/attach&amp;gt; &#039;&#039;(As Is)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Acknowledgements ==&lt;br /&gt;
Many thanks to claesabrandt (the creator of [[Call .NET DLL methods plug-in]]) for the back-and-forth on getting the CLR.dll working smoothly without the need for anything other than .NET 2.0 Framework. That was some great team-work! This tool is awesome and is helping make a potentially ugly install a lot smoother.&lt;br /&gt;
&lt;br /&gt;
== Version History ==&lt;br /&gt;
â€¢ 1.0 First release.&lt;br /&gt;
&lt;br /&gt;
[http://forums.winamp.com/showthread.php?postid=2403963#post2403963 NSIS Forum Thread]&lt;br /&gt;
&lt;br /&gt;
[[Category:Code Examples]]&lt;/div&gt;</summary>
		<author><name>VisualCSharp</name></author>
	</entry>
</feed>