2/26/2006

02-26-06 - 1

02-26-06

Win32 question : I would love my program to act like either a windows program or a console (CLI) app depending on how it's started. eg. if it's run from a DOS prompt (ok, a "cmd" prompt), then act like a console app. If it's started any other way, act like a windows app. The easiest thing is just to make it a console app, but then when I start it as a windows app I get this ugly DOS output box popping up. If I make it a windows app, there must be some way to detect I started from a DOS prompt and hook up my stdin/stdout to that console.

Right now I'm doing two different builds, like this :


#ifdef _CONSOLE
int main(int argc,char *argv[])
{
#else
int CALLBACK WinMain ( IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd )
{
	int argc = __argc;
	char ** argv = __argv;
#endif

and that's super lame.

I find this to be one of those things that's impossible to search for on google. Any kind of search for "WinMain _console" things like that just give you super-basic pages about how to make "Hello World" in Win32. I'm sure someone has done a nice solution for this before, but I've never seen it.

No comments:

old rants