Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^2: pp hide console GUI

by afoken (Canon)
on Apr 21, 2018 at 17:28 UTC ( #1213347=note: print w/replies, xml ) Need Help??

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.


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1213347]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2021-02-25 20:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found