Biff has asked for the wisdom of the Perl Monks concerning the following question:
I keep getting the following pesky little warning messages during an attempt to call the Win32 API GlobalMemoryStatus and I can't understand why.
C:\Documents and Settings\Owner\My Documents\GetInfo>test.pl***BEFORE GMS
Use of uninitialized value in string eq at C:/Perl/site/lib/Win32/API/Struct.pm line 156, <DATA> line 164. Use of uninitialized value in numeric lt (<) at C:/Perl/site/lib/Win32/API/Struct.pm line 214, <DATA> line 164. Use of uninitialized value in numeric lt (<) at C:/Perl/site/lib/Win32/API/Struct.pm line 214, <DATA> line 164. Use of uninitialized value in numeric lt (<) at C:/Perl/site/lib/Win32/API/Struct.pm line 214, <DATA> line 164. Use of uninitialized value in numeric lt (<) at C:/Perl/site/lib/Win32/API/Struct.pm line 214, <DATA> line 164. Use of uninitialized value in numeric lt (<) at C:/Perl/site/lib/Win32/API/Struct.pm line 214, <DATA> line 164. Use of uninitialized value in numeric lt (<) at C:/Perl/site/lib/Win32/API/Struct.pm line 214, <DATA> line 164. Use of uninitialized value in numeric lt (<) at C:/Perl/site/lib/Win32/API/Struct.pm line 214, <DATA> line 164.
...
Use of uninitialized value in numeric lt (<) at C:/Perl/site/lib/Win32/API/Struct.pm line 268, <DATA> line 164. Use of uninitialized value in numeric lt (<) at C:/Perl/site/lib/Win32/API/Struct.pm line 268, <DATA> line 164.
***AFTER GMS
2097024 476436 30988 195568 84 2064472 186736
Actually I first noticed this while trying to use Win32::SystemInfo. The code below is cut from SystemInfo.pm. I've determined that the warnings come from the actual imported call to GlobalMemoryStatus.
Here's the code:
</readmore#!/usr/bin/perl -w use strict; use Data::Dumper; use Win32::API; #================== sub MemoryStatus (\%;$) { #================== # my $return = shift; #hash to return my $ret_type ||= shift || "B"; #what format does the user want? my %fmt_types = ( B => 1, KB => 1024, MB => 1024*1024, GB => 1024*1024*1024); my @params = qw(MemLoad TotalPhys AvailPhys TotalPage AvailPage TotalVirtual AvailVirtual); my %results; #results of fn call my $MemFormat; #divisor for format my $dwMSLength; #validator from fn call $MemFormat = ($ret_type =~ /^[BKMG]B?$/) ? $fmt_types{$ret_type} : $fmt_types{B}; # (See GlobalMemoryStatus on MSDN) # I had to change some of the types to get the struct to # play nicely with Win32::API. The SIZE_T's are actually # DWORDS in previous versions of the Win32 API, so this # change doesn't hurt anything. # The names of the members in the struct are different than # in the API to make my life easier, and to keep the same # return values this method has always had. Win32::API::Struct->typedef( MEMORYSTATUS => qw{ DWORD dwLength; DWORD MemLoad; DWORD TotalPhys; DWORD AvailPhys; DWORD TotalPage; DWORD AvailPage; DWORD TotalVirtual; DWORD AvailVirtual; }); Win32::API->Import('kernel32', 'VOID GlobalMemoryStatus(LPMEMORYSTA +TUS lpMemoryStatus)') or die "Could not locate kernel32.dll - SystemInfo.pm cannot contin +ue\n"; my $MEMORYSTATUS = Win32::API::Struct->new('MEMORYSTATUS'); print "***BEFORE GMS\n"; GlobalMemoryStatus($MEMORYSTATUS); print "***AFTER GMS\n"; return undef if $MEMORYSTATUS->{dwLength} == 0; if (keys(%$return) == 0) { foreach (@params) { $return->{$_} = ($_ eq "MemLoad") ? $MEMORYSTATUS->{$_} : $MEMORYS +TATUS->{$_}/$MemFormat; } } else { foreach (@params){ $return->{$_} = $MEMORYSTATUS->{$_}/$MemFormat unless (!exists($r +eturn->{$_})); } } 1; } my %mh; MemoryStatus(%mh,"KB"); foreach my $k (keys %mh) { print "$mh{$k}\n"; }
janitored by ybiC: Balanced <readmore> tags around longish codeblock, as per Monastery convention
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pesky warnings after calling Win32 API
by ikegami (Patriarch) on Sep 16, 2004 at 22:32 UTC | |
by Biff (Acolyte) on Sep 18, 2004 at 15:07 UTC | |
by ikegami (Patriarch) on Sep 18, 2004 at 18:10 UTC | |
by Biff (Acolyte) on Sep 21, 2004 at 19:15 UTC | |
by ikegami (Patriarch) on Sep 21, 2004 at 19:26 UTC |