我正在尝试GetCaretPos
从 NSIS 安装程序调用 User32.dll 中的函数,而我似乎唯一能得到的是对内存位置错误的无效访问。
这是我的代码:
Function fixUpRegKeyText
Exch $0 ; HWND to text box
Push $1 ; text of edit box
Push $2 ; pointer to point structure
Push $3 ; getlasterror result
System::Alloc 16 ;struct long, long
pop $2
;messageBox MB_OK $2
;get the caret position
System::Call "User32::GetCaretPos(p .r2) i.. ? e"
pop $3
messageBox MB_OK $3 ; 998!
${NSD_GetText} $0 $1
Push $1
call StrUpper
Pop $1
${NSD_SetText} $0 $1
; now set the caret position
;System::call "user32::SetCaretPos(p s.) i .."
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd
编辑如果有人有兴趣使用 Windows API 移动文本插入符号,我在博客上写了它。使用安德斯的答案,在 NSIS 脚本中执行此操作很简单。