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

Hello

I created an exe file with Par::Packer Version 1.006. Because the icon creation failed I was trying to do this manually with the Win32::Exe module Version 0.14.

But here I get the same problem.

use strict; use warnings; use Win32::Exe; my $exe = Win32::Exe->new('test.exe'); $exe = $exe->create_resource_section if !$exe->has_resource_section; $exe->update( icon => 'test.ico', gui => 1); $exe->write('another.exe');

It is not possible to create a resource section.

I get the following errors:

No resource section found in file test.exe at C:/Perl/site/lib/Win32/E +xe.pm line 348. No resource section found in file test.exe at C:/Perl/site/lib/Win32/E +xe.pm line 348. Can't call method "remove" on an undefined value at C:/Perl/site/lib/W +in32/Exe.pm line 473.

I'm using Perl 5.10.1 from Activestate on a Windows XP

Thank you for your help

Greetings

Dirk

Replies are listed 'Best First'.
Re: Win32::Exe - Resource section creation fails
by syphilis (Archbishop) on Sep 23, 2010 at 10:15 UTC
    Because the icon creation failed I was trying to do this manually with the Win32::Exe

    I think PAR::Packer uses Win32::Exe to handle the icon creation in the first place - so if it failed the first time, it's not surprising that it failed again when you repeated the process.

    What version of Windows are you running ? There's a report on the PAR mailing list of a failure (involving icon creation) on Windows 7 that I can't reproduce on Windows Vista.

    The script you posted, works fine for me if I specify 'console' instead of 'gui' ... actually, it may well be working fine for 'gui', too, but I haven't verified that.

    Cheers,
    Rob

      I use Microsoft Windows XP Professional Version 2002 Service Pack 3.

      I think in my case it does not matter if it is gui or console because the creation of a resource section already seems to fail.

      This code

      use strict; use warnings; use Win32::Exe; my $exe = Win32::Exe->new('test.exe'); $exe = $exe->create_resource_section if !$exe->has_resource_section;

      produces this error:

      No resource section found in file test.exe at C:/Perl/site/lib/Win32/E +xe.pm line 348.

      Cheers,

      Dirk

        Now I executed the test of Par::Packer

        Here you can see the result:

        C:\Temp\PAR-Packer-1.006>dmake test C:\Perl\bin\perl.exe -e "chmod(oct('0600'), '..\blib\lib\PAR\StrippedP +ARL\Static.pm');" C:\Perl\bin\perl.exe encode_append.pl static.exe ..\blib\lib\PAR\Strip +pedPARL\Static.pm C:\Perl\bin\perl.exe -e "chmod(oct('0444'), '..\blib\lib\PAR\StrippedP +ARL\Static.pm');" C:\Perl\bin\perl.exe -e "chmod(oct('0600'), '..\blib\lib\PAR\StrippedP +ARL\Dynamic.pm');" C:\Perl\bin\perl.exe encode_append.pl par.exe ..\blib\lib\PAR\Stripped +PARL\Dynamic.pm C:\Perl\bin\perl.exe -e "chmod(oct('0444'), '..\blib\lib\PAR\StrippedP +ARL\Dynamic.pm');" C:\Perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harness(0, ' +inc', 'blib\lib', 'blib\arch')" t/00-pod.t t/10-pa rl-generation.t t/20-pp.t t/30-current_exec.t t/40-packer_cd_option.t t/00-pod.t ............... skipped: Set environment variable PERL_TEST +_POD=1 to test POD t/10-parl-generation.t ... ok t/20-pp.t ................ 31/34 No resource section found in file par +lW2ct.exe at C:/Perl/site/lib/Win32/Exe.pm line 34 8. No resource section found in file parlW2ct.exe at C:/Perl/site/lib/Win +32/Exe.pm line 348. Can't call method "remove" on an undefined value at C:/Perl/site/lib/W +in32/Exe.pm line 473. # Failed test 'pp_gui_tests # amsg572: sub pp_gui_tests cannot system pp --gui --icon hi.ico -o he +llo.exe hello.pl:No such file or directory: # ' t/20-pp.t ................ 32/34 # at automated_pp_test.pl line 8445 +. t/20-pp.t ................ 34/34 # Looks like you failed 1 test of 34. t/20-pp.t ................ Dubious, test returned 1 (wstat 256, 0x100) Failed 1/34 subtests t/30-current_exec.t ...... # Please wait t/30-current_exec.t ...... ok t/40-packer_cd_option.t .. ok Test Summary Report ------------------- t/20-pp.t (Wstat: 256 Tests: 34 Failed: 1) Failed test: 32 Non-zero exit status: 1 Files=5, Tests=71, 487 wallclock secs ( 0.05 usr + 0.03 sys = 0.08 C +PU) Result: FAIL Failed 1/5 test programs. 1/71 subtests failed. dmake.exe: Error code 255, while making 'test_dynamic'

        But the problem seems to be in Win32::Exe and NOT in Par::Packer.

Re: Win32::Exe - Resource section creation fails
by Anonymous Monk on Sep 23, 2010 at 15:31 UTC

    This may or may not help you. But it helped me, with an older version of Par::Packer.

    This problem shows up because of a line in the myldr\Makefile.PL .That file is similar in later versions (for these lines).

    line 70 my $cc = $Config{cc};

    sets this location of the compiler. in my autogenerated Makefile in the same directory is

    line 7 CC=C:/MinGW/bin/gcc.exe

    Line 106 in myldr\Makefile.PL

    } elsif ($cc =~ m/^gcc\b/i or ($cc =~ m/^cc\b/i and $gccversion)) {

    As that line stands, it wants $cc to start with gcc, when it begins with C:/MinGW. So it won't find the $cc

    A solution (good enough for my purposes) was

    line 106:} elsif ($cc =~ m/\bgcc\b/i or ($cc =~ m/^cc\b/i and $gccversion)) {

    The important line that this affects is

    line 111     $res = ($^O =~ /^(?:MSWin|cygwin)/) ? 'win32.coff' : '';

    since we want $res to = 'win32.coff'

    In the autogenerated Makefile, this value shows up in the line for "OBJECTS =", and in the line after "$static.exe".

    Without this change, the Resources Section is never created. But there may be other sources of glitches. If your compiler is not the MinGW gcc, this probably helps little.

      Thank you for your answer. I now tried exactly the same I did with Windows XP with Windows Vista. And there everything is working fine.

      Perhaps it is just a difference how the Makefile is generated. My problem is that I can't try now. I have one week of vacation and here at home I do not have a Windows XP.

      End of next week I'll compare the Makefiles I have on Windows Vista and Windows XP and then I let you know.

      Thank you very very much. You solved my problem.

      I'm very sorry for my late reply.

      To avoid that other people have the same problems I had: Would it make sense to always change line 106 of myldr\Makefile.PL?