You're Making your Visual Studio C++ Projects Wrong
Visual Studio gives two options for creating C++ applications. Console applications use printed text to communicate with the user, harkening back to the pre-GUI days of DOS. The other option is a windowed application with a GUI interface, simply called "Win32 Project" in the Visual Studio project creation dialog.
A console application will use the regular old main function you know and love:
int main(int argc,const char *argv[])
This is cross-platform compatible and runs on any operating system. A "Win32 Project", however, will use a special WinMain() function that only works on Windows:
WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR, int)
So if you don't want a black rectangle printing a bunch of lines of text, you have to use the WinMain() function. But, there is a way to fix this. We can change a console application to a windowed application in the Linker settings in the Visual Studio project settings. Change the Linker > System > Subsystem property to a windowed application.
There's also a way to force the program to use the cross-platform main() function. Change the setting Linker > Options > All Options > Entry Point to mainCRTStartup.
Although the application will no longer show a black text box, the printed output is still detectable by a parent application like the Leadwerks script editor.
However, if you create a .bat file to run your application, you can only pipe the output to a text file. The text will not be shown when the .bat file runs:
MyGame.exe > output.txt
Of course, any Leadwerks game will automatically write it's output to a text log already, so this is sort of redundant. Another consideration is you will not be able to see the output when you run your application from Visual Studio. Strange that VS doesn't support one of the most basic needs of an IDE, and has no known method of viewing the printed output of your program when you run it. However, if you want to get rid of that annoying black popup box, and you want your code to be cross-platform compatible, this is the way to do it.
- 1
3 Comments
Recommended Comments