[rt.cpan.org #94906] Signed return values not working

2014-04-21 Thread mi...@noromaa.fi via RT
Mon Apr 21 08:38:47 2014: Request 94906 was acted upon.
Transaction: Ticket created by mi...@noromaa.fi
   Queue: Win32-API
 Subject: Signed return values not working
   Broken in: (no value)
Severity: (no value)
   Owner: Nobody
  Requestors: mi...@noromaa.fi
  Status: new
 Ticket https://rt.cpan.org/Ticket/Display.html?id=94906 >


Hello!

I am declaring my function as follows:

my $TestFunc = Win32::API->new('PerlWin32.dll', '_TestFunc@24', 'PP',
'i');

The C code looks as follows:

int WINAPI TestFunc(char *str1, char *str2, char *str3, char *str4, char
*str5, char *str6)
{
...
return (-1);
}

On ActiveState Perl 5.16.3 this worked fine and returned -1 to Perl.
However, on ActiveState Perl 5.18.2 the function returns 4294967295.

I am using Win32::API version 0.77. The same problem occurred with version
0.75 that was pre-installed with ActiveState Perl 5.18.2.

When looking at perl -V, I see ActiveState has added USE_64_BIT_INT after
5.16.3. My guess is this affects the way Win32::API handles the return
values. Since I am specifying 'i' (signed int), Win32::API should return -1
to Perl as -1, not as 4294967295. By the way, even 'I' (unsigned int)
returned -1 on ActiveState Perl 5.16.3.

--

Mikko Noromaa (mi...@noromaa.fi) - tel. +358 40 7348034





[rt.cpan.org #119080] Win32::API::Call: parameter X had a buffer overflow with UTF-8 strings

2016-11-30 Thread mi...@noromaa.fi via RT
Wed Nov 30 15:37:46 2016: Request 119080 was acted upon.
Transaction: Ticket created by mi...@noromaa.fi
   Queue: Win32-API
 Subject: Win32::API::Call: parameter X had a buffer overflow with UTF-8 
strings
   Broken in: (no value)
Severity: (no value)
   Owner: Nobody
  Requestors: mi...@noromaa.fi
  Status: new
 Ticket https://rt.cpan.org/Ticket/Display.html?id=119080 >


Hello,

use strict;
use Win32::API;
use Encode;

my $data = Encode::decode('UTF-8',"The price is \xe2\x82\xac5.");

my $WriteFile = Win32::API->new('kernel32.dll', 'WriteFile', 'IPIPI', 'i')
or die "Unable to load WriteFile: $!";

my $written = " " x 4;
$WriteFile->Call(0, $data, 4, $written, 0);

This fails with:

Win32::API::Call: parameter 2 had a buffer overflow

Tested on ActiveState Perl v. 5.22.1 and 5.18.2, Win::API versions 0.84,
0.82 and 0.75. Same problem happened on all of them.

--

Mikko Noromaa (mi...@noromaa.fi) - tel. +358 40 7348034