Greetings Monks,

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:

#!/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"; }
</readmore

janitored by ybiC: Balanced <readmore> tags around longish codeblock, as per Monastery convention


In reply to Pesky warnings after calling Win32 API by Biff

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.