Windows App with Console Running [SOLVED]

Started by golite, October 01, 2013, 02:55:58 AM

Previous topic - Next topic

golite

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.


TimoVJL

Example in source code:#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

Thank you very much. That worked just fine.

Persay

Great you found out and shared ! Can you also update the thread title prepending [solved] :)

henrin

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

frankie

Quote from: henrin 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  ::)
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