Updated and unicode version from this one.
Note that I will giving updates via github instead of this thread. Use this thread for support or questions.
Go to Github repository for latest versions.
Dialogs v3 (unicode) nsis plugin
8 posts
Nice work.
One observation, when you are allocating memory for the buffer, the sizing appears to be wrong. string_size is the number of characters, for ansi this is fine as they are one byte each. Under unicode the size is two bytes, so the actual length allocated is half. So the 'correct' way is sizeof(TCHAR)*string_size.
I also see a mixing of unicode only functions and TCHAR strings, this would break the ansi build. Is this intentional or a mistake?
Also, to help remove connections to the CRT, change ZeroMemory() to SecureZeroMemory(). Oh, and swap _tsclen() for lstrlen(), and _sntprintf() for wnsprintf(), and _ttoi() for myatoi() (provided by the plugin api). Use Dependency Walker to confirm that MSVCRTx0.DLL isn't in the list.
Just as a side note, the callback functions return type is usually an LRESULT, but since INT_PTR is the same width I guess it doesn't make any difference.
Sorry for nitpicking, I just ported Afrow UK's PassDialog plugin from char only to unicode and 64 bit, and I still have a bit of a buzz from it.
One observation, when you are allocating memory for the buffer, the sizing appears to be wrong. string_size is the number of characters, for ansi this is fine as they are one byte each. Under unicode the size is two bytes, so the actual length allocated is half. So the 'correct' way is sizeof(TCHAR)*string_size.
I also see a mixing of unicode only functions and TCHAR strings, this would break the ansi build. Is this intentional or a mistake?
Also, to help remove connections to the CRT, change ZeroMemory() to SecureZeroMemory(). Oh, and swap _tsclen() for lstrlen(), and _sntprintf() for wnsprintf(), and _ttoi() for myatoi() (provided by the plugin api). Use Dependency Walker to confirm that MSVCRTx0.DLL isn't in the list.
Just as a side note, the callback functions return type is usually an LRESULT, but since INT_PTR is the same width I guess it doesn't make any difference.
Sorry for nitpicking, I just ported Afrow UK's PassDialog plugin from char only to unicode and 64 bit, and I still have a bit of a buzz from it.
Hi Jason.
1.- Thanks for the sizeof(TCHAR)*string_size tip.
2.- Is intentional, because I don't think there is sane machine running windows Me or lower. Either less, this plugin is for unicode machines (sorry ANSI users, you'll have to compile into ANSI if you want this char type support)
3.- Yup, I'll change the functions as you pointed.
1.- Thanks for the sizeof(TCHAR)*string_size tip.
2.- Is intentional, because I don't think there is sane machine running windows Me or lower. Either less, this plugin is for unicode machines (sorry ANSI users, you'll have to compile into ANSI if you want this char type support)
3.- Yup, I'll change the functions as you pointed.
thanks mr Joel
my problem solve with new plugin:
is not possible change this unicode plugin to ansi?! Finally,we have two plug-ins (Unicode-Ansi)?
my problem solve with new plugin:
!include "LogicLib.nsh"
SetCompressor /SOLID lzma
Name "InputBox"
OutFile "InputBox.exe"
RequestExecutionLevel user
ShowInstDetails show
Unicode true
XPStyle on
!define Password "12345"
Page instfiles
# Just for testing
!addplugindir /x86-unicode "..\bin"
Function .onInit
InitPluginsDir
; InputBox dialog:
; Type: 0=text,1=password
; Dialog title, max 64 chars
; Secundary text, max 64 chars
; label ok, max 12 chars
; label cancel, max 12 chars
; Return var for the button pressed: 0=cancel, 1=ok
; Return var with the inputed text
Loop1:
Dialogs::Ver 9
Dialogs::InputBox 1 "PasswordBox $9" "Please a enter Password..." "OK" "Close" 4 6
${if} $4 == 1
;----------------------------
Var /GLOBAL Len
StrLen $Len "$6"
${If} "$Len" > "25"
MessageBox MB_OK|MB_ICONINFORMATION "You entered $Len character,Maximum password length is limited to 25 character."
Goto Loop1
${EndIf}
;----------------------------
${If} "$6" == ""
MessageBox MB_OK|MB_ICONINFORMATION "Please enter a password to continue..."
Goto Loop1
${EndIf}
;----------------------------
${If} "$6" != "${Password}"
MessageBox MB_OK|MB_ICONSTOP "The password '$6' is correct!"
Goto Loop1
${EndIf}
;----------------------------
${If} "$6" == "${Password}"
MessageBox MB_OK|MB_ICONINFORMATION "Welcome To Application..."
${EndIf}
;----------------------------
${endif}
FunctionEnd
Section ""
SectionEnd just a question:is not possible change this unicode plugin to ansi?! Finally,we have two plug-ins (Unicode-Ansi)?
Wow, two plugin requests in two days, your on a roll.
It'll be just simple to remove the explicit unicode functions in the code and add the option to build unicode or ansi in cmake. In a few days you can visit github for updates.
Looking good.
Another observation, wsnprintf() expects the number of characters, not the number of bytes. So it's enough to use string_size, provided that the allocation used sizeof(TCHAR)*string_size.
That's a common mistake to make, some require the size in bytes (sizeof(TCHAR)*string_size), others require the length in characters (string_size). Another way to get the character length is: sizeof(buff)/sizeof(buff[0]).
Another observation, wsnprintf() expects the number of characters, not the number of bytes. So it's enough to use string_size, provided that the allocation used sizeof(TCHAR)*string_size.
That's a common mistake to make, some require the size in bytes (sizeof(TCHAR)*string_size), others require the length in characters (string_size). Another way to get the character length is: sizeof(buff)/sizeof(buff[0]).
Damn, win api 😛
I'll change the wnsprintf parameter to string_size in the next release. -_-
I'll change the wnsprintf parameter to string_size in the next release. -_-