Hi,
The exec image produced by Win32::Exe using nm.ico and runner.exe is not
corrupted. After updating you can see the icon images for the executable
in explorer, you can view the version information etc etc.
The issue is that originally, runner.exe has three icon resources named
IDI_APPICON, IDI_DOCUMENT and #32512
Within the runner.exe code attempts are probably made to load the
resource named IDI_APPICON, which fail and give the spurious 'not a
valid application' messages.
Your code change replaces all existing icon resources with a copy of
nm.ico, but keeps the original names. This happens to work for
runner.exe but is a big change in behaviour for the method set_icons.
The Windows resource loading methods are inconsistent (clearly). It
would appear that when a resource with id IDI_APPICON is requested, IF
this is not present Windows defaults to the first GROUPICON and must
find an icon of the requested type in there. If, however, IDI_APPICON is
found, Windows is not so fussy about finding the exact type in it and
will convert the nearest compatible type. Hence, existing Win32::Exe
code works with an.ico, which has necessary 32 bit images, but not with
nm.ico. If, however, a resource with IDI_APPICON is created, it
apparently does not matter what gets stuffed in there.
Anyhow, I would think if you are changing the icons of an application
that expects certain things at certain id's, that is going to be
application specific and not something that can or should be dealt with
by the generic 'set_icons' method.
I shall use your code as the basis for adding a few methods
'list_groupicon_names'
'replace_group_icon' (takes a groupicon name and an iconfile)
'remove_group_icon' ( takes a groupicon name )
so that if you know what you want to do, it is possible without having
to write the raw code.
Thanks
Mark
On Fri Apr 02 14:20:21 2010, RPKELLY wrote:
Show quoted text> Sometimes, Win32::Exe will write back a corrupted EXE which cannot be
> run when setting the icon files in the executable. Attached are two
icon
Show quoted text> files, and an exe. Using an.ico will not corrupt the executable, but
> nm.ico will. Altering sub "set_icons" in Win32/Exe.pm to the following
> fixes the issue:
>
> sub set_icons {
> my ($self, $icons) = @_;
>
> my $rsrc = $self->resource_section;
>
> my @gicons = $rsrc->objects('GroupIcon');
> foreach my $gicon (@gicons) {
> my $group = $self->require_class('Resource::GroupIcon')->new;
> $group->SetPathName($gicon->PathName);
> $group->set_parent($rsrc);
> $rsrc->insert($group->PathName, $group);
>
> $group->set_icons($icons);
> $group->refresh;
> }
> }
>
> Note that making this change will cause test #12 (line 41) in file
> 2-icon.t to fail because the size of the resulting executable is
larger.
Show quoted text>
> Thanks,
> -Ryan Kelly