Updated example functions in the main documentation

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7168 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2020-04-14 17:37:58 +00:00
parent b704d52400
commit 13121dacfe
3 changed files with 111 additions and 183 deletions

View file

@ -170,7 +170,6 @@ First you have to change the output directory to that where the DLL you want to
The following code fragment will install 'condmgr.dll' to a temporary directory, execute the CmGetHotSyncExecPath function and display returned data.
Save this script
\c ; **** snip ****
\c Function loadDll
\c
\c SetOutPath $TEMP\eInspect ; create temp directory
@ -182,7 +181,6 @@ Save this script
\c DetailPrint "Return value: $2"
\c
\c FunctionEnd
\c ; **** snip ****
and this function produces the following output in the 'details' page:
@ -194,11 +192,11 @@ Path length: 24 \\<br\\>
Return value: 0
Written by \W{http://nsis.sourceforge.net/archive/profile.php?userid=78}{djc}
Written by \W{https://web.archive.org/web/2018/http://nsis.sourceforge.net/archive/profile.php?userid=78}{djc}
\\<u\\>Acknowledgements & Thanks\\</u\\> \\<br\\>
Lots of thanks go to \\<b\\>kichik\\</b\\> and \\<b\\>Sunjammer\\</b\\> for spending a lot of time assisting in solving this problem. Also to \\<b\\>brainsucker\\</b\\> for creating the System.dll plug-in in the first place.
Good Luck!
\# \\<u\\>Acknowledgements & Thanks\\</u\\> \\<br\\>
\# Lots of thanks go to \\<b\\>kichik\\</b\\> and \\<b\\>Sunjammer\\</b\\> for spending a lot of time assisting in solving this problem. Also to \\<b\\>brainsucker\\</b\\> for creating the System.dll plug-in in the first place.
\# Good Luck!
\H{dumplogtofile} Dump Content of Log Window to File
@ -208,17 +206,24 @@ To use it, push a file name and call it. It will dump the log to the file specif
\c GetTempFileName $0
\c DetailPrint "Writing log to $0"
\c Push $0
\c Call DumpLog
If you're building a \R{intro-unicode}{Unicode installer} you can \cw{!define DumpLog_As_UTF16LE} to output as UTF-16LE or \cw{!define DumpLog_As_UTF16LE "/BOM"} to output as UTF-16LE with a BOM.
Here is the function:
\c !define LVM_GETITEMCOUNT 0x1004
\c !define LVM_GETITEMTEXTA 0x102D
\c
\c Function DumpLog # Written by KiCHiK
\c !define /IfNDef LVM_GETITEMCOUNT 0x1004
\c !define /IfNDef LVM_GETITEMTEXTA 0x102D
\c !define /IfNDef LVM_GETITEMTEXTW 0x1073
\c !if "${NSIS_CHAR_SIZE}" > 1
\c !define /IfNDef LVM_GETITEMTEXT ${LVM_GETITEMTEXTW}
\c !else
\c !define /IfNDef LVM_GETITEMTEXT ${LVM_GETITEMTEXTA}
\c !endif
\c
\c Function DumpLog
\c Exch $5
\c Push $0
\c Push $1
@ -226,82 +231,29 @@ Here is the function:
\c Push $3
\c Push $4
\c Push $6
\c
\c FindWindow $0 "#32770" "" $HWNDPARENT
\c GetDlgItem $0 $0 1016
\c StrCmp $0 0 error
\c StrCmp $0 0 exit
\c FileOpen $5 $5 "w"
\c StrCmp $5 0 error
\c StrCmp $5 "" exit
\c SendMessage $0 ${LVM_GETITEMCOUNT} 0 0 $6
\c System::StrAlloc ${NSIS_MAX_STRLEN}
\c Pop $3
\c System::Call '*(&t${NSIS_MAX_STRLEN})p.r3'
\c StrCpy $2 0
\c System::Call "*(i, i, i, i, i, i, i, i, i) p \
\c (0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1"
\c System::Call "*(i, i, i, i, i, p, i, i, i) i (0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1"
\c loop: StrCmp $2 $6 done
\c System::Call "User32::SendMessageA(p, i, p, p) i \
\c ($0, ${LVM_GETITEMTEXTA}, $2, r1)"
\c System::Call "User32::SendMessage(i, i, i, i) i ($0, ${LVM_GETITEMTEXT}, $2, r1)"
\c System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)"
\c FileWrite $5 "$4$\r$\n"
\c !ifdef DumpLog_As_UTF16LE
\c FileWriteUTF16LE ${DumpLog_As_UTF16LE} $5 "$4$\r$\n"
\c !else
\c FileWrite $5 "$4$\r$\n" ; Unicode will be translated to ANSI!
\c !endif
\c IntOp $2 $2 + 1
\c Goto loop
\c done:
\c FileClose $5
\c System::Free $1
\c System::Free $3
\c Goto exit
\c error:
\c MessageBox MB_OK error
\c exit:
\c Pop $6
\c Pop $4
\c Pop $3
\c Pop $2
\c Pop $1
\c Pop $0
\c Exch $5
\c FunctionEnd
Here's the function to generate a UTF-16LE file if you're building a \R{intro-unicode}{Unicode installer}.
\c !define LVM_GETITEMCOUNT 0x1004
\c !define LVM_GETITEMTEXTW 0x1073
\c
\c Function DumpLog # Written by KiCHiK, modified by Jim Park
\c Exch $5
\c Push $0
\c Push $1
\c Push $2
\c Push $3
\c Push $4
\c Push $6
\c
\c FindWindow $0 "#32770" "" $HWNDPARENT
\c GetDlgItem $0 $0 1016
\c StrCmp $0 0 error
\c FileOpen $5 $5 "w"
\c FileWriteWord $5 0xfeff ; Write the BOM
\c StrCmp $5 0 error
\c SendMessage $0 ${LVM_GETITEMCOUNT} 0 0 $6
\c System::StrAlloc ${NSIS_MAX_STRLEN}
\c Pop $3
\c StrCpy $2 0
\c System::Call "*(i, i, i, i, i, i, i, i, i) p \
\c (0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1"
\c loop: StrCmp $2 $6 done
\c System::Call "User32::SendMessageW(p, i, p, p) i \
\c ($0, ${LVM_GETITEMTEXTW}, $2, r1)"
\c System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)"
\c FileWriteUTF16LE $5 "$4$\r$\n"
\c IntOp $2 $2 + 1
\c Goto loop
\c done:
\c FileClose $5
\c System::Free $1
\c System::Free $3
\c Goto exit
\c error:
\c MessageBox MB_OK error
\c exit:
\c Pop $6
\c Pop $4
@ -314,8 +266,7 @@ Here's the function to generate a UTF-16LE file if you're building a \R{intro-un
\H{readreg_multi_sz} How to Read REG_MULTI_SZ Values
KiCHiK wrote this script to help rpetges in \W{http://forums.winamp.com/showthread.php?s=&threadid=131154}{this forum thread}. It reads a registry value of the type REG_MULTI_SZ and prints it out. Don't forget to edit where it says "Edit this!" when you test this script. The values must point to a REG_MULTI_SZ value or the example will spit out an error.
\#{KiCHiK wrote this script to help rpetges in \W{http://forums.winamp.com/showthread.php?s=&threadid=131154}{this forum thread}.} This example reads a registry value of the type REG_MULTI_SZ and prints it out. Don't forget to edit where it says "Edit this!" when you test this script. The values must point to a REG_MULTI_SZ value or the example will spit out an error.
\c OutFile "REG_MULTI_SZ Reader.exe"
\c Name "REG_MULTI_SZ Reader"
@ -342,25 +293,24 @@ KiCHiK wrote this script to help rpetges in \W{http://forums.winamp.com/showthre
\c !define REG_LINK 6
\c !define REG_MULTI_SZ 7
\c
\c !define RegOpenKeyEx "Advapi32::RegOpenKeyExA(i, t, i, i, *i) i"
\c !define RegQueryValueEx "Advapi32::RegQueryValueExA(i, t, i, *i, i, *i) i"
\c !define RegCloseKey "Advapi32::RegCloseKeyA(i) i"
\c !define RegOpenKeyEx "Advapi32::RegOpenKeyEx(p, t, i, i, *p) i"
\c !define RegQueryValueEx "Advapi32::RegQueryValueEx(p, t, p, *i, p, *i) i"
\c !define RegCloseKey "Advapi32::RegCloseKeyA(p) i"
\c
\c ####### Edit this!
\c
\c !define ROOT_KEY ${HKEY_CURRENT_USER}
\c !define SUB_KEY "Software\Joe Software"
\c !define VALUE "Strings"
\c !define ROOT_KEY ${HKEY_LOCAL_MACHINE}
\c !define SUB_KEY "SYSTEM\CurrentControlSet\Control\Lsa"
\c !define VALUE "Security Packages"
\c
\c ####### Stop editing
\c
\c Section "Read"
\c StrCpy $0 ""
\c StrCpy $1 ""
\c StrCpy $2 ""
\c StrCpy $3 ""
\c System::Call "${RegOpenKeyEx}(${ROOT_KEY}, '${SUB_KEY}', \
\c 0, ${KEY_QUERY_VALUE}|${KEY_ENUMERATE_SUB_KEYS}, .r0) .r3"
\c 0, ${KEY_QUERY_VALUE}|${KEY_ENUMERATE_SUB_KEYS}, 0 r0) .r3"
\c
\c StrCmp $3 0 goon
\c MessageBox MB_OK|MB_ICONSTOP "Can't open registry key! ($3)"
@ -376,7 +326,7 @@ KiCHiK wrote this script to help rpetges in \W{http://forums.winamp.com/showthre
\c read:
\c
\c StrCmp $1 ${REG_MULTI_SZ} multisz
\c MessageBox MB_OK|MB_ICONSTOP "Registry value no REG_MULTI_SZ! ($3)"
\c MessageBox MB_OK|MB_ICONSTOP "Registry value not a REG_MULTI_SZ! ($3)"
\c Goto done
\c
\c multisz:
@ -412,8 +362,11 @@ KiCHiK wrote this script to help rpetges in \W{http://forums.winamp.com/showthre
\c StrCmp $3 "" done
\c DetailPrint $3
\c StrLen $5 $3
\c IntOp $4 $4 + $5
\c IntOp $4 $4 + 1
\c !if "${NSIS_CHAR_SIZE}" > 1
\c IntOp $5 $5 * ${NSIS_CHAR_SIZE}
\c !endif
\c IntPtrOp $4 $4 + $5
\c IntPtrOp $4 $4 + ${NSIS_CHAR_SIZE}
\c Goto loop
\c
\c done:
@ -429,4 +382,4 @@ KiCHiK wrote this script to help rpetges in \W{http://forums.winamp.com/showthre
\H{unicode_defines}Predefined Macros for Unicode support
There are two macros that can help you write scripts that work for both Unicode and ANSI installers. To figure out if the script is being compiled to generate a Unicode installer, use !ifdef to check for $\{NSIS_UNICODE\}. To see what the size of a character is, use $\{NSIS_CHAR_SIZE\}. It will be 1 for ANSI and 2 for Unicode installers.
There are two macros that can help you write scripts that work for both Unicode and ANSI installers. To figure out if the script is being compiled to generate a Unicode installer, use !ifdef to check for NSIS_UNICODE. To see what the size of a character is, use $\{NSIS_CHAR_SIZE\}. It will be 1 for ANSI and 2 for Unicode installers.