mdog has asked for the wisdom of the Perl Monks concerning the following question:

Brethern --

Knowing that super search is my friend, I found this node that addresses this very issue.

So I go and download the appropriate DLL referenced in the article and looking at the documentation for Win32::API to import functions from DLLs and come up with the following code:

use Win32::API; my $idleTrackerInitHandle = Win32::API->new( "C:\\Perl\\dvl\\itunes\\IdleTrac.dll", "int IdleTrackerInit()" ); my $result = $idleTrackerInitHandle->Call(); #my $idleTrackerInitHandle = Win32::API->new( # "IdleTrac", "int IdleTrackerInit()" # ); #my $result = $idleTrackerInitHandle->Call(); #$function = Win32::API->new( # 'IdleTrac, 'int idleTrackerInitHandle-()', # ); # $return = $function->Call();
Where the DLL is in the same dir as the script, in windows/system, windows/system32, etc...

And the result I get is always: Can't call method "Call" on an undefined value at C:\Perl\dvl\itunes\GetIdleTime.pl line 6, <DATA> line 164.

I have never tried importing functions from a DLL before but when I tried the samples on the Win32::API doc pages, those worked fine. I tried the above code and a bunch more (passing parameters, etc) but cannot get it to work.

Does anyone know what I am doing wrong?

Many thanks,
mdog

Replies are listed 'Best First'.
Re: Get idle time on a Windows box (die)
by tye (Sage) on Jul 29, 2005 at 21:45 UTC

    > perldoc Win32::API

    Note that "Import" returns 1 on success and 0 on failure (in which case you can check the content of $^E).

    So there's a good chance that is also useful if new() fails:

    my $idleTrackerInitHand­le = Win32::API->new( "C:\\Perl\\dvl\\itun­es\\IdleTrac.dll", "int IdleTrackerInit() +" ) or die "Can't import IdleTrackerInit: $^E\n";

    And solve whatever problem this points to.

    - tye        

Re: Get idle time on a Windows box
by Ace128 (Hermit) on Aug 03, 2005 at 07:36 UTC
    Or you can do: http://www.perlmonks.org/?node_id=480378 ?
      Cool! Looks like your answer was posted after my original question or I wouldn't have wasted folks time...Thanks a ton!
        Hehe, you just gotta love Perl eh? :)