in reply to Re^9: Can't change icon with win32 module
in thread Can't change icon with win32 module
Here is mine
#!/usr/bin/perl -- use strict; use warnings; use Win32::GUI(); use Win32::API; Win32::API->Import('kernel32','BOOL SetConsoleIcon(HWND icon)'); @ARGV or @ARGV = map { glob $_ } "C:/Progra~1/*.ico", "C:/Progra~1/*/*.ico", "C:/Progra~1/*/*/*.ico", "C:/Progra~1/*/*/*/*.ico", #~ "C:/Progra~1/*/*/*/*/*.ico", "C:/WINDOWS/*/*.ico", "C:/WINDOWS/*/*/*.ico", "C:/WINDOWS/*/*/*/*.ico", #~ "C:/WINDOWS/*/*/*/*/*.ico", #~ "C:/WINDOWS/*/*/*/*/*/*.ico", #~ "C:/WINDOWS/*/*/*/*/*/*/*.ico", ;;;; for my $file ( @ARGV ){ print "$file\n"; eval { my $icon = Win32::GUI::Icon->new( $file ) or die sprintf qq/ErrIcon \$!(%d)(%s)\n\$^E(%d)(%s)\nGLS(% +d)(%s)/, $!,$!,$^E,$^E, Win32::GetLastError(), Win32::FormatMessage(Win32::GetLastError()) ;;;;; SetConsoleIcon( $icon->{-handle} ) or die sprintf qq/ErrSet \$!(%d)(%s)\n\$^E(%d)(%s)\nGLS(%d +)(%s)/, $!,$!,$^E,$^E, Win32::GetLastError(), Win32::FormatMessage(Win32::GetLastError()) ;;;;; 1; } or warn "$@\n\n"; sleep 1; } SetConsoleIcon( undef );## restore __END__ $ perl sicon.pl sicon.pl perlmonks.favicon.ico sicon.pl sicon.pl ErrIcon $!(2)(No such file or directory) $^E(0)() GLS(0)(The operation completed successfully. ) at sicon.pl line 25. perlmonks.favicon.ico sicon.pl ErrIcon $!(2)(No such file or directory) $^E(0)() GLS(0)(The operation completed successfully. ) at sicon.pl line 25.
Obviously sicon.pl isn't an .ico file
Looking at these results and Win32::GUI::Icon docs, it is now obvious that it doesn't preserve $^E from the 2-3 ways it tries to load the file, so $^E ends up being uninformative
FormatMessage() OTOH assumes 0 means success where as $^E doesn't
Since this program works for me for about a dozen icon files I find in program files
I must assume there is something wrong with your box2.ico
good luck figuring it out :) You might hack on some GUI.xs to insert informative diagnostics, or hit up MSDN for specs regarding icon files so you can compare them to box2.ico ...
In Section
Seekers of Perl Wisdom