Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Win32::API question

by patgas (Friar)
on Nov 02, 2001 at 00:44 UTC ( #122666=perlquestion: print w/replies, xml ) Need Help??

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

I'm learning how to use Win32::API to change my desktop wallpaper. Of course, things are not working correctly or else I wouldn't be posting here. :) I keep getting this error:

Wrong number of parameters: expected 0, got 4.

There's a couple different ways I can take this, and none of them present any obvious solution to me. The API call does expect 4 parameters, which I think I've set up. I've gone back and forth through the POD for Win32::API and I'm stuck. Can anyone tell me what I'm doing wrong?

#!/usr/bin/perl -w use strict; use LWP::Simple; use Win32::API; my ( $day, $month, $year ) = (localtime)[3..5]; my $date = sprintf( "%4s%02s%02s", $year += 1900, ++$month, $day ); my $filename = 'c:\perl\penny-arcade.gif'; print "Fetching:$year/${date}h.gif +\n"; #my $gif = get( "$year/${date}h.gif +" ); my $gif = get( "" + ); die "Could not retrieve GIF: $!" unless defined $gif; open GIF, ">$filename" or die "Can't open $filename: $!"; binmode GIF; print GIF $gif; close GIF; my $SysParam = new Win32::API( 'User32', 'SystemParametersInfo', 'NNPN +', 'N' ); die "Can't import API SystemParametersInfo: $!" unless defined $SysPar +am; $SysParam->Call( 20, 0, $filename, \x1 );

"We're experiencing some Godzilla-related turbulence..."

Replies are listed 'Best First'.
Re: Win32::API question
by RhetTbull (Curate) on Nov 02, 2001 at 01:41 UTC
    It looks ok except for the \x1 in the line
    $SysParam->Call( 20, 0, $filename, \x1 ); That causes the following error under use strict; "Bareword "x1" not allowed while "strict subs" in use"

    Not sure what you were trying to do with that? The last parameter should be a 1 or 0.

    Note that this unfortunately will not change the wallpaper if you use ActiveDesktop (at least on NT/Win2K). I haven't figured out a way to change the ActiveDesktop wallpaper from perl yet. It will change the wallpaper you see when the screen is locked or logged out but not the ActiveDesktop wallpaper (what's on your desktop when you're using the computer).

    Update:I just recalled that in the past with certain versions of Win32::API and ActiveState perl (don't recall which) I had trouble with the parameters string for Win32::API. If you still have trouble, try changing your method import line to this (use an array ref instead of a string):

    my $SysParam = new Win32::API( 'User32', 'SystemParametersInfo', [ qw( +N N P N) ], 'N' );

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://122666]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2021-04-20 13:23 GMT
Find Nodes?
    Voting Booth?

    No recent polls found