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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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

In reply to Re^2: pp hide console GUI by afoken
in thread pp hide console GUI by IB2017

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (6)
    As of 2021-02-25 19:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?