Win32 :: SerialPort constructor overflows buffer when setting reference variable

This works well:

my $PortObj;    
$PortObj = new Win32::SerialPort ("COM12") || die "Can't open COM\n";

However, when I try to provide a variable instead of “COM12” from the TK entry, like this:

my $portNumVar = "12";
my $portNum = $mw->Entry(-justify=>'center',-width=>'5',-textvariable=>\$portNumVar)->pack();

Inside the subprogram (after pressing the button):

my $PortObj;
my $com = "COM".$portNumVar;
print $com;
$PortObj = new Win32::SerialPort ($com) || die "Can't open COM\n";

I get this error:

Win32 :: API :: Call: parameter 1 had a buffer overflow on C: /Perlx86_5.16/site/lib/Win32API/CommPort.pm line 176.

How is this possible? Shouldn't it be?

Thanks Mark.

+4
source share
2 answers

Got the same issue with Wx and Win32 :: SerialPort. In my case, this workaround worked:   $PortObj = new Win32::SerialPort (eval(qq("$com"))) || die "Can't open COM\n";

+3
source

, ( \$val), , ().

my $com = "COM".$$portNumVar;
-1

All Articles