Author Topic: GetCursorPos does not return y coordinate  (Read 10866 times)

Offline HD1920.1

  • Jr. Member
  • *
  • Posts: 40
GetCursorPos does not return y coordinate
« on: May 07, 2014, 05:52:03 PM »
Hello guys, I have just another problem. When I try to get the current cursor position with GetCursorPos and display the result with printf, only the x coordinate is shown. The y coordinate is zero. Where is my mistake? Code:
Code: [Select]
struc POINT
.x_coord: resq 1
.y_coord: resq 1
.limit:
endstruc

extern GetCursorPos
extern printf
extern exit
global Start

section .text
Start:
sub rsp, 0x28

mov rcx, Cursor
call GetCursorPos

mov rcx, format
mov rdx, [Cursor + POINT.x_coord]
mov r8, [Cursor + POINT.y_coord]
call printf

xor rcx, rcx
call exit
add rsp, 0x28
ret

section .data
Cursor: istruc POINT
iend
format: db "Cursor is at (%u, %u)", 10, 0


Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: GetCursorPos does not return y coordinate
« Reply #1 on: May 09, 2014, 01:17:03 AM »
Look at the definition of POINT:
Code: [Select]
typedef struct tagPOINT {
  LONG x;
  LONG y;
} POINT, *PPOINT;
A LONG is 32 bits in size, a LONG LONG is 64 bits in size, you are declaring your structure improperly.

You create your structure with qwords:
Code: [Select]
struc POINT
.x_coord: resq 1
.y_coord: resq 1
.limit:
endstruc

Instead, it should be with DWORDS:
Code: [Select]
struc POINT
.x_coord: resd 1
.y_coord: resd 1
.limit:
endstruc

Offline HD1920.1

  • Jr. Member
  • *
  • Posts: 40
Re: GetCursorPos does not return y coordinate
« Reply #2 on: May 09, 2014, 02:34:39 PM »
Thank you very much, now it works. I thought that I have to use qwords because I'm programing in 64 bits.

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: GetCursorPos does not return y coordinate
« Reply #3 on: May 09, 2014, 03:42:12 PM »
Thank you very much, now it works. I thought that I have to use qwords because I'm programing in 64 bits.

Nope.  You'll find many structure definitions for 64-bit operating systems contain 32/16/8 bit sized members.  BUT ( there's always a but ) YOU need to ensure the proper alignment of the data members when defining the structure itself.