我的问题是在Windows 10机器上从GetWindowPlacement获取一个WINDOWPLACEMENT结构。我得到了一个有效的窗口句柄,并且创建该结构看起来不错,但是调用GetWindowPlacement失败。下面是我的代码:
#!/usr/bin/perl
use strict;
use warnings;
use Win32::API;
my $wpl; # WINDOWPLACEMENT structure
my $hwnd;
my $rv;
Win32::API->Import("user32", "FindWindow", "PP", "N");
Win32::API->Import("user32", "GetWindowPlacement", "NP", "I");
Win32::API::Struct->typedef( 'POINT', qw(
LONG x;
LONG y;
));
Win32::API::Struct->typedef( 'RECT', qw(
LONG left;
LONG top;
LONG right;
LONG bottom;
));
Win32::API::Struct->typedef( 'WINDOWPLACEMENT', qw(
UINT length;
UINT flags;
UINT showCmd;
POINT ptMinPosition;
POINT ptMaxPosition;
RECT rcNormalPosition;
RECT rcDevice;
));
$hwnd = FindWindow('SciCalc', 0);
print("window handle: $hwnd\n");
$wpl = Win32::API::Struct->new( 'WINDOWPLACEMENT' );
$wpl->{length} = Win32::API::Struct::sizeof($wpl);
print("pointer: $wpl\n");
print("length: $wpl->{length}\n");
$rv = GetWindowPlacement($hwnd, $wpl);
print("return value: $rv\n");
exit(0);
__END__
结果是:
window handle: 722532
pointer: Win32::API::Struct=HASH(0x2609b60)
length: 60
Win32::API::Call: parameter 2 had a buffer overflow at C:\Users\ma\MyFolder\test\winpos.pl line 41.
使用AutoIt 3获取WINDOWPLACEMENT结构会得到:
![AutoIt 3结果] AutoIt3
1条答案
按热度按时间hgc7kmma1#
解决办法是改变:
至:
在documentation中找到。