Solved

Warning using Win32::API

Posted on 2004-08-24
10
762 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Expert Comment

by:boazgOLD
Comment Utility
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
Comment Utility
uh, that sucks.
is it not possible to call the INIT manually? i just don`t want to change module code.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

by:boazgOLD
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
bad news :-(
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now