05 Feb 2012, 04:38
Generic-user-small

Dat Nguyen (25 posts)

require ‘win32/api’
include Win32

def getCursorPos
=begin
BOOL WINAPI GetCursorPos( __out LPPOINT lpPoint
);
=end API.new ‘GetCursorPos’, ’?’, ’?’, ‘user32’
end

How do I define the getCursorPos function?
How do I prepare the parameter to call it?
How do I extract the (x, y) values from the call?

Thanks,
Dat

05 Feb 2012, 06:03
Mr_sketchy_pragsmall

Ian Dees (192 posts)

Hello, Dat.

GetCursorPos takes a pointer to a POINT structure, and returns a <a href="mailto:BOOL”>BOOL@. So the declaration is similar to the GetWindowRect example on page 20, something like this:

get_cursor_pos = API.new 'GetCursorPos', 'P', 'I', 'user32'

To pass in a POINT struct, you can pack the integers into a string:

point = [0, 0].pack 'L*'
get_cursor_pos.call point
x, y = point.unpack 'L*'

—Ian

05 Feb 2012, 07:11
Generic-user-small

Dat Nguyen (25 posts)

Ian:
Bunch of Thanks!
-Dat

  You must be logged in to comment