I have a small game made in visual studio 2013, written in c++. It creates a window in which it draws several things and pops up the console I used to debug. The problem is: if I click on the "exit" button from the menu I introduced, all things good, the process is terminated as it should be; if I press the 'X' (close) button on top of the window, it closes the window, but the console still remains. As it should be excepted, not having the console enabled doesn't fix anything: there are no windows associated with the game, but the sound still plays and the process still exists in task manager. I've searched a lot about this and I couldn't find a solution for this issue.
I've tried with atexit, but the program doesn't go to the function written for atexit. Maybe I'm placing it wrong, I can't tell. This is what I've tried.
void close_win() {
if (engine)
engine->drop();
/*if (SC_CLOSE) {
cout << "sc_close";
_exit(0);
}*/
cout << "Ceva ";
exit(0);
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("Aarghhh! O ramaaa !");
createMenu();
glClearColor(0.0, 0.0, 0.0, 0.0);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(dreptunghi);
glutSpecialFunc(player);
glutMainLoop();
atexit(close_win);
return 0;
}
or
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
if (CEvent == CTRL_CLOSE_EVENT)
{
cout << "You are closing my program.";
}
return TRUE;
} if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE) == FALSE)
{
cout << "The handler is not going to work.";
}
or
if (glutGetWindow == 0)
exit(0);
The game was made without classes, using OpenGL and GLUT libraries, if it matters for anything.
Also, when I set a breakpoint to atexit and use step over, after 2 steps the debug stops with "sehprolg4.asm not found". Does any of this has to do with the fact that the function doesn't call close_win()?