Solved

Warning using Win32::API

Posted on 2004-08-24
10
765 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 500 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

805 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