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

My machine is 64 b ... pack('NC',$size,$aKey).
  1. Firstly, template char 'N' is a 32-bit unsigned integer in network (big-endian) order.

    If you are running Windows on Intel (90%+ are), then you would need 'V' which is 32-bit unsigned in VAX (little-endian) order.

  2. But ... as you are on 64-bit OS, if you are running a 64-bit perl: (you don't say?)

    Then size_t will equate to a 64-bit unsigned int which would be template 'Q'.

The simplest template would be 'J' which should work for 32-bit or 64-bit. (Excepting 32-bit perl's compiled for 64-bit ints.)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: Low-level version of Win32::API::Struct
by sgv_81 (Novice) on Aug 01, 2012 at 16:21 UTC

    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?

      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.