Um, I'm afraid that is too many words for me :) but

#!/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/GetCur +sorPos.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::Stru +ct"), ] 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

So I'm not sure what the docs are talking about if its a bug or whatever :)

update: Win32::API says

Note that this works only when the function wants a pointer to a structure: as you can see, our structure is named 'POINT', but the API used 'LPPOINT'. 'LP' is automatically added at the beginning of the structure name when feeding it to a Win32::API call.

update: See http://cpansearch.perl.org/src/COSIMO/Win32-API-0.68/Callback/t/03_Jim_Shaw.t

my $pid_raw_value = "\x0" x Win32::API::Type->sizeof("LPDWORD"); GetWindowThreadProcessId($hwnd, $pid_raw_value); my $window_pid = Win32::API::Type::Unpack("LPDWORD", $pid_raw_valu +e);

So now I think this is leftover documentation of a feature that was never implemented ( a more complete OO interface, because the tie is cumbersome). Documentation definitely needs improvement.

Up to always i've been using pack/unpack myself but I don't use Win32::API too much


In reply to Re: Win32::API::Struct pointer by Anonymous Monk
in thread Win32::API::Struct pointer by rovingeyes

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.