in reply to Re: Low-level version of Win32::API::Struct
in thread Low-level version of Win32::API::Struct

Thank you, I understand that I'm in the wierd option of 32 bit perl for 64 int, Intel and Windows XP (but perl running through Cygwin). I think your post will be very helpful when I make the simplified example from my previous post work and I move into the original problem.

As a quick refresh, the simplified example from my previous post:

#### import an API that uses this structure my $getCursor = new Win32::API('user32', 'GetCursorPos','S','N'); #### create a 'POINT' object $lpPoint=pack('LL',0,0); #### call the function passing our structure object $getCursor->Call($lpPoint); #### and now, access its members my ($x,$y) = unpack('LL',$pt); print "The cursor is at: ".$x.", ".$y."\n";
No matter which parameter I use within pack ('J','L','N','Q' or 'V') in $lpPoint=pack('LL',0,0); I still get the error "Can't call method Pack on a undefined value". The error pops up in $getCursor->Call($lpPoint);.

From CPAN doc on Win32::API seems that I can substitute the Win32::API::Struct for the packed variable and then pass it to the Win32::API object. Any idea what I'm missing?

Replies are listed 'Best First'.
Re^3: Low-level version of Win32::API::Struct
by bulk88 (Priest) on Aug 01, 2012 at 17:32 UTC
    That is not an example from the docs.

    my $getCursor = new Win32::API('user32', 'GetCursorPos','S','N');
    should be
    my $getCursor = new Win32::API('user32', 'GetCursorPos','P','N');
    since $lpPoint is a scalar string formally. 'S'/'T' are only for ::Struct objects. The result of pack() is a scalar string. Not a blessed object. If you had a newer version of ::API, you would get a proper croak message
    croak("Win32::API::Call: parameter %d must be +a%s", i+1, " Win32::API::Struct object!\n");
    much better than 0.68 blindly doing ->Pack() on whatever scalar happens to fall in as argument which is what is happening in your case.