NO

Author Topic: Windows App with Console Running [SOLVED]  (Read 12427 times)

golite

  • Guest
Windows App with Console Running [SOLVED]
« on: October 01, 2013, 02:55:58 AM »
Where do I apply the following POLINK option? This is copied from the help files. I need to understand it.

To be able to write information to the screen the process must have access to a console window. This is normally not the case for a GUI program, which is expected to create it's own windows. You can make sure the process have access to a console window by adding the following POLINK options:

-subsystem:console -entry:_WinMainCRTStartup. You should only use this in debug builds.

« Last Edit: March 18, 2014, 05:30:55 PM by frankie »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Windows App with Console Running
« Reply #1 on: October 01, 2013, 03:31:58 PM »
Example in source code:
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#define _DEBUG

#ifdef _DEBUG
#include <stdio.h>
#pragma comment(linker, "-subsystem:console")
#pragma comment(linker, "-entry:WinMainCRTStartup")
#endif

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
#ifdef _DEBUG
printf("to console\n");
#endif
MessageBox(0, "Test1", "Test1", MB_OK);
return 0;
}
May the source be with you

golite

  • Guest
Re: Windows App with Console Running
« Reply #2 on: October 02, 2013, 03:25:20 PM »
Thank you very much. That worked just fine.

Persay

  • Guest
Re: Windows App with Console Running
« Reply #3 on: March 04, 2014, 10:18:48 AM »
Great you found out and shared ! Can you also update the thread title prepending [solved] :)

henrin

  • Guest
Re: Windows App with Console Running [SOLVED]
« Reply #4 on: November 05, 2014, 03:55:49 PM »
In a recent program I have written:

int __stdcall WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR CmdLine, int CmdShow)
{
   AllocConsole() ;
   ...
   _cprintf(fmt, ...) ;

and it worked.
I do not know why  ::)

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Windows App with Console Running [SOLVED]
« Reply #5 on: November 05, 2014, 05:31:34 PM »
In a recent program I have written:

int __stdcall WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR CmdLine, int CmdShow)
{
   AllocConsole() ;
   ...
   _cprintf(fmt, ...) ;

and it worked.
I do not know why  ::)
Yes these are console output functions that directly write to the console window, so they always work.
The other method, using the standard stream functions (fprintf, etc) let you use all features of a consolle (redirection, etc).
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide