Skip to content
⌘ NSIS Forum Archive

How to convert string to UCS-2LE

4 posts

eugene25#

How to convert string to UCS-2LE

The problem is to convert string into Unicode form UCS-2LE, here the sample.
input: 12345
output UCS2-LE string of bytes: 31003200330034003500
Any idea how to solve it?
JasonFriday13#
First of all, NSIS Unicode 2.46.5 is a fork of the official package, so we can't provide any support for it.

Try the latest NSIS 3.x release, as the NSIS 3.x releases support both ansi and unicode. To compile a unicode installer, use 'Unicode True'. Put the string into the script and the compiler should convert it for you.
Anders#
!define EMPTY ""
StrCpy $0 "12345"
StrCpy $1 0
StrCpy $2 ""
loop:
StrCpy $3 $0 1 $1
StrCmp "" $3 done
System::Call 'kernel32::lstrcpyW(*i.r4,wr3)'
IntFmt $4 %x $4
StrLen $3 $4
IntCmp $3 4 +3
StrCpy $4 $4${EMPTY}0
Goto -3
StrCpy $2 $2$4
IntOp $1 $1 + 1
Goto loop
done:
DetailPrint $2
If you need to deal with things outside the ASCII range in a specific codepage you should call MultiByteToWideChar...