[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[no subject]
Especially also note that the "GUI" vs. "console" field in the .exe
header doesn't have any effect on whether the application can have a
GUI or not.
It's perfectly possible to use editbin to change the executable of,
for instance, Notepad, into a console executable. It will work as
before, but just open a console window (to which it won't print
anything). Note that you have to copy notepad.exe from its normal
location first so that Windows's automatic security mechanism won't
restore it to its original state thinking some tampering is going on.
> Does anybody have an idea how to solve this problem?
If you don't want to build two otherwise identical copies of the
"prog" program (the only difference being that one is linked with
-mwindows and the other one not), one trick could be to use the new
AttachConsole() API that is present in Windows XP and later. Compile
this sample program and check how it works when run from a shell in a
console, or from Explorer. Borrow ideas from this:
#include <stdio.h>
#define _WIN32_WINNT 0x0500
#include <windows.h>
int
main (int argc, char **argv)
{
int allocated_new_console = FALSE;
if (!AttachConsole (ATTACH_PARENT_PROCESS))
{
if (!AllocConsole ())
{
MessageBox (NULL,
"Could not either attach to parent's console or
allocate a new console.",
"Error",
MB_ICONEXCLAMATION|MB_OK);
exit (1);
}
allocated_new_console = TRUE;
}
freopen ("CONOUT$", "w", stdout);
if (allocated_new_console)
printf ("Could not attach to parent's console, had to allocate a
new one, sorry.\n");
printf ("Hello there!\n");
Sleep (10000);
return 0;
}
In your case you would not have the branch where AllocConsole() is
called. Just try AttachConsole(ATTACH_PARENT_PROCESS) and if that
works, reopen stdout to the console that the process now has. Should
work like a dream.
--tml
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]