Subject: | Resulf of ::Type::Pack and ::Type::Unpack discarded |
Win32::API::Type::Pack returns the packed argument while its caller
expects the argument to be changed in-place. The same goes for
Win32::API::Type::Unpack.
I thought the fix would be simple:
--------------- BEGIN Type.pm diff ---------------
...
sub Pack {
- my ($type, $arg) = @_;
+ my $type = $_[0];
+ #my $arg = $_[1];
my $pack_type = packing($type);
- if($pack_type eq 'p') {
- $pack_type = 'Z*';
+ if($pack_type eq 'c') {
+ DEBUG "(PM)Type::Pack: got packing 'c': leaving untouched\n";
+ return;
}
- $arg = pack($pack_type, $arg);
-
- return $arg;
+ DEBUG "(PM)Type::Pack: packing '$type' '$pack_type' '$_[1]'\n";
+ $_[1] = pack($pack_type, $_[1]);
+ DEBUG "(PM)Type::Pack: returning '$_[1]'\n";
}
sub Unpack {
- my ($type, $arg) = @_;
+ my $type = $_[0];
+ #my $arg = $_[1];
my $pack_type = packing($type);
- if($pack_type eq 'p') {
- DEBUG "(PM)Type::Unpack: got packing 'p': is a pointer\n";
- $pack_type = 'Z*';
+ if($pack_type eq 'c') {
+ #DEBUG "(PM)Type::Unpack: got packing 'c': assuming a string
(XXX)\n";
+ #$pack_type = 'Z*';
+ DEBUG "(PM)Type::Pack: got packing 'c': leaving untouched (XXX)\n";
+ return;
}
- DEBUG "(PM)Type::Unpack: unpacking '$pack_type' '$arg'\n";
- $arg = unpack($pack_type, $arg);
- DEBUG "(PM)Type::Unpack: returning '$arg'\n";
- return $arg;
+ DEBUG "(PM)Type::Unpack: unpacking '$type' '$pack_type' '$_[1]'\n";
+ $_[1] = unpack($pack_type, $_[1]);
+ DEBUG "(PM)Type::Unpack: returning '$_[1]'\n";
}
...
--------------- END Type.pm diff ---------------
But that that breaks USHORT* vs LPWSTR, for starters.
In fact, fixing this problem would require addressing Win32::API's
failure to differentiate between
- a pointer to a signed/unsigned character (CHAR*/BYTE*/...)
- a pointer to a buffer (LPVOID)
- a pointer to a variable string (LPSTR)
- a pointer to a constant string (LPCSTR)
and between
- a pointer to a signed/unsigned short (SHORT*/USHORT*/...)
- a pointer to a variable wide string (LPWSTR)
- a pointer to a constant wide string (LPCWSTR)
I'm willing to work on this, but I'd need the source to API_test.dll to
add tests.