Hello monks.

I'm having an odd problem with Win32::API, but I don't believe it's a bug in the module, but rather something that I've missed.

The problem is that the code below runs fine by itself, but when I put it in a module which I use from my main script I get the following error:

Win32::API::parse_prototype: WARNING unknown output parameter type 'BO +OL' at C:/Perl/site/lib/Win32/API.pm line 273.
It seems to me that the problem might be related to namespacing or perhaps some obscure scoping rule - please enlighten me as to what I've overlooked here. I've tried changing the return type to INT and BYTE with the same result.
use strict; use warnings; use Win32::API; Win32::API::Struct->typedef(SYSTEM_POWER_STATUS => qw ( BYTE ACLineStatus; BYTE BatteryFlag; BYTE BatteryLifePercent; BYTE Reserved1; DWORD BatteryLifeTime; DWORD BatteryFullLifeTime; )); my $bar = Win32::API->new('kernel32','BOOL GetSystemPowerStatus(SYSTEM +_POWER_STATUS status)'); my $foo = Win32::API::Struct->new('SYSTEM_POWER_STATUS'); $bar->Call($foo); foreach (qw( ACLineStatus BatteryFlag BatteryLifePercent Reserved1 + BatteryLifeTime BatteryFullLifeTime)) { print "$_: $foo->{$_}\n"; } }
Updated
I don't blame you for not replying yet - I can't reproduce the error if I write a module with the posted code from scratch, so something else must be going on in my script...

Another update Okay, I found a way to make it work/not work.
It turns out that for the package to work, the datastructure as well as the function (basically all the code I posted) needs to be written inside the function that I call in the package...I'd like to know why this is the case, though :-p


In reply to Win32::API missing types by Nemurenai

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.