Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Leadwerks Company Blog

  • entries
    179
  • comments
    1,161
  • views
    337,139

Contributors to this blog

You're Making your Visual Studio C++ Projects Wrong


Admin

3,714 views

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.

 

vs.jpg

 

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.

 

console.jpg

 

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.

 

main.jpg

 

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.

 

scripteditor.jpg

 

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.

3 Comments


Recommended Comments

You can also use this at the top of App.cpp

 

#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")

 

Running it from Visual Studio will still create the window but won't print anything to it. Running straight from the EXE won't create the window at all.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Facebook Twitter Youtube Github Steam
×
×
  • Create New...