GetCaretPos错误无效的访问内存位置

时间:2011-06-17 00:40:56

标签: winapi nsis getcaretpos

我正在尝试从NSIS安装程序调用User32.dll中的GetCaretPos函数,我唯一能看到的是对内存位置错误的无效访问。

这是我的代码:

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移动文本插入符感兴趣,我blogged about it。使用anders的答案,可以直接在NSIS脚本中执行此操作。

1 个答案:

答案 0 :(得分: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