consoleless app
Hi, does anyone know how to run an "int main()" app without it opening a console window? (Win32 platform)
If you're talking about writing an app that doesn't open a console, then you need to move into 'proper' windows programming, which has a different entry point - use WinMain(blah) instead of main(void). If you don't need any kind of user interface then it should be no problem, but if you need anything more complex than a Message Box, then you may need to get your hands dirty with real windows programming.
If it's just a case of running an existing console app without it popping up a console window, if you run it from a shortcut you can specify startup options, like run minimized etc. This doesn't actually stop it opening a console window, but it does keep it out the way a bit.
If it's just a case of running an existing console app without it popping up a console window, if you run it from a shortcut you can specify startup options, like run minimized etc. This doesn't actually stop it opening a console window, but it does keep it out the way a bit.
The reason I ask is because SDL can be started from a main() instead of a WinMain(), so that your main program can be platform independent. I want this support in the engine i'm working on, and i wonder how it is possible.
You can use conditional compilation to choose the entry point depending on what platform you're compiling on:
#ifdef _WIN32 // included only on Windows int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int cmdShow)#else int main(int argc, char** argv, char** envp)#endif{ // the rest of your program return 0;}
figured it out by digging around in the SDL source:
goes something like this...
[main.cpp]
#include "main.h"
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
{
return(main());
}
[main.h]
extern int main();
then in the prog just call main() as normal.
goes something like this...
[main.cpp]
#include "main.h"
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
{
return(main());
}
[main.h]
extern int main();
then in the prog just call main() as normal.
Quote:Original post by JohnHurt
The reason I ask is because SDL can be started from a main() instead of a WinMain(), so that your main program can be platform independent. I want this support in the engine i'm working on, and i wonder how it is possible.
i assume it works with preprocessor magic
something similar to
#define main(a,b) WinMain(bar,a,b)
Edit: You found it faster, i haven't had the source right now...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement