Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: pp hide console GUI

by dasgar (Priest)
on Apr 21, 2018 at 16:49 UTC ( #1213343=note: print w/replies, xml ) Need Help??


in reply to pp hide console GUI

I have never used Tk, but I have used Win32::GUI. It's been a while since I have used Win32::GUI, but I thought that there was something in the module related to this.

The Win32::GUI tutorial part 9 discusses this issue. It covers what needs to be done to perl.exe and that ActiveState Perl has a perlw.exe executable with this modification. In Strawberry Perl, I see a wperl.exe, which could be the equivalent of ActiveState's perlw.exe.

Combining the above information, it might be possible to modify pp to use wperl.exe instead of perl.exe to bundle your code into an executable without the console window.

Replies are listed 'Best First'.
Re^2: pp hide console GUI
by afoken (Canon) on Apr 21, 2018 at 17:28 UTC

    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". ;-)
Re^2: pp hide console GUI
by IB2017 (Pilgrim) on Apr 21, 2018 at 17:22 UTC

    I've already realized that creating GUI tools for distributions is quite an hazardous enterprise in Perl (being PerlApp discontinued, which in the past was a good solution for me). I should have choose another language, but now it is too late, and I have to find compromises... (pp doesn't allow to change the exe icon!!!) I'll have a look at the suggested post. In the meantime I tested perl2exe and it works fine in hiding (from the beginning) the console. It has also a quite basic option to change the exe icon. Both tools have been able to package my Tk application (with about 40 modules).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2021-09-28 05:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?