Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

pp hide console GUI

by IB2017 (Pilgrim)
on Apr 21, 2018 at 12:48 UTC ( #1213329=perlquestion: print w/replies, xml ) Need Help??

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

Dear monks

Here I am again with the following question. When I pack my Tk app with pp, The -gui option hides the console window. However, however when I lunch the application, the console window is displayed for a fraction of a second, to be then hidden. Is this a feature, a bug, or something I have to live with? It is not the end of the world... but it is not really how it should be in a GUI application.

I am on Windows 10, perl 5.16, and I have the latest pp installed

Replies are listed 'Best First'.
Re: pp hide console GUI
by jonadab (Parson) on Apr 21, 2018 at 15:48 UTC

    In general, there's quite a lot about $foo that doesn't very closely match how things really ought to be in a GUI, for $foo in ("Tk", "Windows Ten").

    With that said, this could be just as much a Perl issue (or at least a Perl on Windows issue) as anything. I don't know if there's a proper solution.

Re: pp hide console GUI
by dasgar (Priest) on Apr 21, 2018 at 16:49 UTC

    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.

      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". ;-)

      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).

Re: pp hide console GUI (citrusutils cavapackager)
by Anonymous Monk on Apr 21, 2018 at 23:12 UTC
      Win32::Exe has issues for a long time Bug #110605 for Win32-Exe: exe_update produces broken EXE file when ProductName/FileDescription is specified

      Well, it should be quite easy to patch the console/windowed flag in the EXE file without Win32::Exe. Wikipedia has a nice overview image in Portable Executable, and Microsoft currently offers a detailed description in PE Format (Windows). The relevant field is located in the optional headers, section Windows-specific fields. Its name is simply "Subsystem" and should contain a value documented in Windows Subsystem. IMAGE_SUBSYSTEM_WINDOWS_GUI = 2 indicates a windowed application, IMAGE_SUBSYSTEM_WINDOWS_CUI = 3 indicates a console application. There are more valid values, including OS/2, POSIX subsystem, drivers, EFI and XBOX stuff.

      Alexander

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

      Citrusperl/Cavapackager: never been able to match the right citrusperl with cavapackager. Cavapackager always complained that perl - no matter which version I installed and set in cavapackager - was not compatible...

        Cool story

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1213329]
Approved by marto
help
Chatterbox?
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-03-04 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (104 votes). Check out past polls.

    Notices?