Skip to content
⌘ NSIS Forum Archive

System Plug-in SetConsoleCursorPosition

5 posts

KnightRiderX#

System Plug-in SetConsoleCursorPosition

Hello everyone.

I need to set console cursor position; I've read about NSIS System Plug-in, tried different cases but I still have no luck with passing COORD structure to function. I'm seeking for a help, thank you.

Test Example:


; get console handle - everything is fine at that part; console attached and works
System::Call "kernel32::AttachConsole(i -1)i .r0"
StrCmp $0 0 end
System::Call "kernel32::GetStdHandle(i -11)i .r0"

; the problem is below
; create struct
System::Call "*(i 2, i 3) p.s"
Pop $8
System::Call "kernel32::SetConsoleCursorPosition(i r0, p r8)" ; first param works, but not second
System::Free $8
What is wrong there?

Regards, KR
Anders#
COORD is not a pointer to a struct, it is two 16-bit numbers packed into a int32 so just use a plain "i" parameter. I believe one of our .nsh files has a MAKELONG macro you can use to build the packed number.
Anders#
If the position is known at compile time you can also give it as a direct parameter.

!include WinCore.nsh
Section
System::Call "kernel32::AttachConsole(i -1)i .r0"
StrCmp $0 0 end
System::Call "kernel32::GetStdHandle(i -11)p .r0"

${MAKELONG} $1 $2 2 3
System::Call "kernel32::SetConsoleCursorPosition(p r0, i r1)" ; From MAKELONG
IntFmt $1 "%#.8x" $1
DetailPrint $1

Sleep 2222

System::Call "kernel32::SetConsoleCursorPosition(p r0, i 0x00050003)" ; Packing as hex INT32 directly
SectionEnd
Not sure why you think you need to move the cursor though. Writing to stdout will never be perfect because NSIS is really a GUI app.
Nutzzz#
Originally Posted by Anders View Post
Writing to stdout will never be perfect because NSIS is really a GUI app.
I know you know this, Anders, but for KnightRiderX's edification, you can do a custom build of NSIS, adding the parameter "NSIS_CONFIG_LOG_STDOUT=yes" to your scons command.