Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Warning using Win32::API

Posted on 2004-08-24
10
Medium Priority
?
792 Views
Last Modified: 2009-12-16
i use the following code to use a dll - function:

use Win32::API;
$timer = Win32::API->new( "winmm.dll", "long timeGetTime()" );

but the module complains

>> Win32::API::parse_prototype: WARNING unknown output parameter type 'long' at C:/Perl/site/lib/Win32/API.pm line 273.

Why is this? "int" doesn´t work also.
To me it seems to be a bug in the module.
0
Comment
Question by:holli
  • 5
  • 4
10 Comments
 
LVL 8

Expert Comment

by:inq123
ID: 11885234
Hi holli,

This may not help, but does it work that you change it to LONG or INT?

Cheers!
0
 
LVL 1

Accepted Solution

by:
boazgOLD earned 2000 total points
ID: 11886601
try using
Win32::API->Import( "winmm.dll", "long timeGetTime()" );
instead of
Win32::API->new( "winmm.dll", "long timeGetTime()" );

seems to get around it on my computer...

then all you have to do is call timeGetTime()

example

use Win32::API;
Win32::API->Import( "winmm.dll", "long timeGetTime()" );
print timeGetTime();

hope that helps...
0
 
LVL 6

Author Comment

by:holli
ID: 11889674
i forgot to say, that i use the module in a WSH/PerlScript - file (*.wsf)
all perl code in such files is implicitly eval()ed.
so the code:

use Win32::API;
Win32::API->Import( "winmm.dll", "I timeGetTime()" );
print timeGetTime();

works fine, but this:

eval
qq{
  use Win32::API;
  Win32::API->Import( "winmm.dll", "I timeGetTime()" );
  print timeGetTime();
};

does not (prints the same warning as mentioned above).

inq,
changing long to LONG has no effect.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:boazgOLD
ID: 11890718
it would seem that INIT sections are not called when in eval()
you have to call them yourself
there is an INIT section in Type.pm responsibe of loading the types and their meanings.

solution:
in Win32/API/Type.pm find the init section (there is only one), and copy it into a function, name it something like eval_init, and call it before using win32::API

use Win32::API;
Win32::API::Type::eval_init();
$timer = Win32::API->new( "winmm.dll", "long timeGetTime()" );

if you dont feel like finding the init and stuff, you can just copy mine:


sub eval_init
{
    my $section = 'nothing';
    foreach (<DATA>) {
        next if /^\s*#/ or /^\s*$/;
        chomp;
        if( /\[(.+)\]/) {
            $section = $1;
            next;
        }
        if($section eq 'TYPE') {
            my($name, $packing) = split(/\s+/);
            # DEBUG "(PM)Type::INIT: Known('$name') => '$packing'\n";
            $Known{$name} = $packing;
        } elsif($section eq 'PACKSIZE') {
            my($packing, $size) = split(/\s+/);
            # DEBUG "(PM)Type::INIT: PackSize('$packing') => '$size'\n";
            $PackSize{$packing} = $size;
        } elsif($section eq 'MODIFIER') {
            my($modifier, $mapto) = split(/\s+/, $_, 2);
            my %maps = ();
            foreach my $item (split(/\s+/, $mapto)) {
                my($k, $v) = split(/=/, $item);
                $maps{$k} = $v;
            }          
            # DEBUG "(PM)Type::INIT: Modifier('$modifier') => '%maps'\n";
            $Modifier{$modifier} = { %maps };
        } elsif($section eq 'POINTER') {
            my($pointer, $pointto) = split(/\s+/);
            # DEBUG "(PM)Type::INIT: Pointer('$pointer') => '$pointto'\n";
            $Pointer{$pointer} = $pointto;
        }
    }
}



stick that in type.pm and all should be well!

hope that helps
0
 
LVL 6

Author Comment

by:holli
ID: 11891227
uh, that sucks.
is it not possible to call the INIT manually? i just don`t want to change module code.
0
 
LVL 1

Expert Comment

by:boazgOLD
ID: 11892422
if you want to avoid changing the module code, you can add the code to the module at runtime:

$function = sub {

# INIT code here....
};
*Win32::API::Type::eval_init=$function;

can create a new module (Win32::API::EvalCompatible for example) whos is to add the code and execute it;

hope that helps


0
 
LVL 6

Author Comment

by:holli
ID: 11900361
why can´t i just Module::INIT()?
isn´t it supposed to be a function like any other?
It must have a entry in the Symbol table?
if so, it should be possible to get a ref to this symbol.
0
 
LVL 6

Author Comment

by:holli
ID: 11900628
i did a little investigation.

package t;

sub INIT
{
      print "INIT";
}

sub import
{
   my ($pkg, @args) = @_;
   print "package $pkg loaded, args ", join(':',@args), "\n";
   @foo::args = @args;
 
   my $init = $t::{INIT};
   my $foo  = $t::{foo};
   $init = \&$init;
   $foo = \&$foo;
   print "* $init *";
   print "* $foo *";
   &foo();
   &$init();
   print "end";
}

sub foo
{
      print "FOO";      
}

1;

______________


#t.pl
use lib qw (c:/ );
use t qw (x y);
print "main";


outcome:
package t loaded, args x:y
Undefined subroutine &t::INIT called at c://t.pm line 21.
BEGIN failed--compilation aborted at c:\t.pl line 2.
* CODE(0x186a230) ** CODE(0x186a170) *FOO


Why?
"CODE(0x186a230)" looks like a code-reference. why can´t i call it?

0
 
LVL 1

Expert Comment

by:boazgOLD
ID: 11901239
INIT is not a subroutene. INIT is a block of code. the only way init is diferent from just any code between curley brackets is in that is is executed as soon as compiled, thus being useful for running initialisation code. you can have multiple INIT blocks. none of them are subroutenes, and none of them can be called.
0
 
LVL 6

Author Comment

by:holli
ID: 11901358
bad news :-(
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question