http://qs321.pair.com?node_id=1213347


in reply to Re: pp hide console GUI
in thread pp hide console GUI

No big hacking required, changing a flag in the final EXE file is sufficient. Here is a part of an old script that patches a generated executable, using Win32::Exe:

#!/usr/bin/perl -w use strict; # ... use Win32::Exe; # ... my $console=0; # originally from script arguments my $stub="stub.exe"; # originally from script arguments my $out="out.exe"; # originally from script arguments # ... my $exe=Win32::Exe->new($stub) or die "$stub: $!"; $exe->SetSubsystem($console ? 'console' : 'windows'); $exe->write($out);

People with some experience in programming Windows applications in C or C++ might be a little bit irritated, because console applications start at int main(int argc, char ** argv), whereas windowed applications start at int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow). But that's already an illusion, program execution starts somewhere deep in the runtime library, which then either calls main() or WinMain(), depending on how the program was compiled. The linker records the setting (console or windowed) in the EXE file. The final executable does not care about that flag, it calls whatever entry point was compiled in.

The main difference is that Windows does not allocate or reuse a console window for programs that have the flag set to windowed instead of console. Some programs that expect to have a console window might be a little bit irritated, but perl usually just works.

One obvious problem is that you can't see any errors reported by perl, as perl simply writes to STDERR. No console, no error message. So you may want to modify the main program a little bit. Wrapping almost everything in a single eval BLOCK and showing a messagebox using Win32::MsgBox containing $@ if any error occurs is helpful at least during debugging.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)