0

我正在尝试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 脚本中执行此操作很简单。

4

1 回答 1

1

p 指针类型在 2.46 中不起作用,使用 i。(使用您的离线帮助文件,在线帮助文​​件具有仅在 SVN 中可用的功能)

此外,当函数需要指向您已分配的结构的指针时,请使用“i register”,而不是“i .register”(该函数需要知道内存地址以便用数据填充它)

System::Call '*(i,i)i.r0'
System::Call "USER32::GetCaretPos(i r0)i.r3"
System::Call '*$0(i.r1,i.r2)'
DetailPrint "$1x$2 return=$3"
System::Free $0
于 2011-06-17T14:26:47.133 回答