简体   繁体   中英

NSIS ListView - GetItemText returns wrong value


I try to create the Windows installer using ListView. I am able to insert item to list view:

# put the plugin version to list view (in my case value 2.2)
${NSD_LV_InsertItem} $list $i '$5' 

However when I try to read the value from given index:

# get selected item plugin version
${NSD_LV_GetItemText} $list 0 0 $R0
MessageBox MB_OK "The text of item 0 is: $R0"

I got message: The text of item 0 is: ▯2
Why is not output displayed correctly?

Thank you!

"▯2" is the "2.2" ASCII string viewed as a UTF-16LE string.

The 3rd-party CommCtrl.nsh file is buggy, you need to make sure the LVM_* defines are correct for your target.

!include nsDialogs.nsh
!include WinMessages.nsh ; The 3rd-party CommCtrl.nsh file is buggy, include this first to make sure LVM_* is defined correctly
!ifndef LVM_GETITEMTEXT
!define /math LVM_GETITEMTEXTA ${LVM_FIRST} + 45
!define /math LVM_GETITEMTEXTW ${LVM_FIRST} + 115
${_NSIS_DEFAW} LVM_GETITEMTEXT
!endif
!include "CommCtrl.nsh"
!define /ifndef _COMMCTRL_NSH_VERBOSE ${_COMMCTRL_VERBOSE}

Page Custom MyPage

Var /Global List
Var /Global i

Function MyPage
nsDialogs::Create 1018
Pop $0

${NSD_CreateListView} 0u 0u 300u 50% "Listview"
Pop $list
StrCpy $i 0
StrCpy $5 "2.2"
${NSD_LV_InsertColumn} $list 0 200 "column 0"
${NSD_LV_InsertItem} $list $i '$5' 

${NSD_CreateButton} 0 60% 100% 13u "MsgBox item 0"
Pop $0
${NSD_OnClick} $0 DisplayItem0

nsDialogs::Show
FunctionEnd

Function DisplayItem0
Pop $R0
${NSD_LV_GetItemText} $list 0 0 $R0
MessageBox MB_OK "The text of item 0 is: $R0"
FunctionEnd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM