codekiddy
codekiddy

Reputation: 6137

setup visual studio to windows subsystem with openGL?

How do I setup my project so that it opens a window instead of console?

#include <GL\glew.h>
#include <GL\glfw.h>

int main()
{
    glfwInit();
    glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
    glfwTerminate();
    return 0;
}

This code opens a window but it also opens a console, how do setup my project so that only window appear? Using VS 2010.

Upvotes: 2

Views: 593

Answers (3)

mpet
mpet

Reputation: 1014

Use

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)

instead of

int main()

and set SubSystem to Windows (/SUBSYSTEM:WINDOWS) in Project properties/Linker/System

Don't forget to add

#include "Windows.h"

Upvotes: 0

datenwolf
datenwolf

Reputation: 162164

See my answer here: https://stackoverflow.com/a/6882500/524368

(Verbatim quote):


In the project build linker options set

/SUBSYSTEM:windows
/ENTRY:mainCRTStartup

Or use the following #pragma in the source file with the int main(...)

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

Upvotes: 3

Jerry Coffin
Jerry Coffin

Reputation: 490178

The linker automatically assumes you want to use the console subsystem when you have a function named main. A few obvious (but untested) possibilities would be:

  1. Use an entry-point named WinMain
  2. Explicitly specify -subsystem:windows to the linker
  3. (1|2) use a completely different entry point, tell the linker both the entry point and the subsystem.

Upvotes: 2

Related Questions