#!/usr/bin/perl -- use strict; use warnings; use Data::Dump; use Win32::API; #~ $Win32::API::DEBUG = 666; #~ http://cpansearch.perl.org/src/COSIMO/Win32-API-0.68/samples/GetCursorPos.pl use Win32::API; Win32::API::Struct->typedef( POINT => qw( LONG x; LONG y; ) ); Win32::API->Import('user32' => 'BOOL GetCursorPos(LPPOINT pt)'); #### using OO semantics my $pt = Win32::API::Struct->new('POINT'); GetCursorPos($pt) or die "GetCursorPos failed: $^E"; print "Cursor is at: $pt->{x}, $pt->{y}\n"; #### using tie semantics my %pt; tie %pt, 'Win32::API::Struct' => 'POINT'; GetCursorPos(\%pt) or die "GetCursorPos failed: $^E"; print "Cursor is at: $pt{x}, $pt{y}\n"; { my $pt = Win32::API::Struct->new('POINT'); my $lpt = Win32::API::Struct->new('LPPOINT'); dd [ $pt, $lpt ]; GetCursorPos($pt) or die "GetCursorPos failed: $^E"; dd ['winner', $pt ]; GetCursorPos($lpt) or die "GetCursorPos failed: $^E"; dd [ 'dud', $lpt ]; print "Cursor is at: $pt->{x}, $pt->{y}\n"; } __END__ Cursor is at: 266, 336 Cursor is at: 266, 336 [ bless({ __typedef__ => "POINT", typedef => [["x", "l", "LONG"], ["y", "l", "LONG"]], }, "Win32::API::Struct"), bless({ __typedef__ => "LPPOINT", typedef => [] }, "Win32::API::Struct"), ] do { my $a = [ "winner", bless({ __typedef__ => "POINT", buffer => "\n\1\0\0P\1\0\0", buffer_recipients => ['fix', 'fix'], typedef => [["x", "l", "LONG"], ["y", "l", "LONG"]], x => 266, y => 336, }, "Win32::API::Struct"), ]; $a->[1]{buffer_recipients}[0] = $a->[1]; $a->[1]{buffer_recipients}[1] = $a->[1]; $a; } [ "dud", bless({ __typedef__ => "LPPOINT", buffer => "", buffer_recipients => [], typedef => [], }, "Win32::API::Struct"), ] Cursor is at: 266, 336