glutInit() troubles...

After a long lapse in doing anything OpenGL-related, I've forgotten pretty much everything and am learning OpenGL again from scratch. As expected, the hello-world window program doesn't work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <GL\glew.h>
#include <GL\freeglut.h>

int main(int argc, char** argv)
{
	//Initialise GLUT
	glutInit(&argc, argv);
	//Initialise display mode + window
	glutInitDisplayMode(GLUT_SINGLE);
	glutInitWindowSize(800,600);
	glutInitWindowPosition(100,100);
	//Create the window
	glutCreateWindow("It worked... what a miracle");
	return 0;
}

It crashes on the very first function (glutInit()) with an access violation. Presumably because I set main as the entry point but it's a Win32 app. If I add some 'fake' command line arguments before the call, it works:
1
2
argc = 1;
argv[0] = "OpenGL_app";

However this means my program won't ever be able to use real command line arguments. So I was wondering... is there a way to get around this, and to make argc and argv work in a Win32 app?
Yes, you can use GetCommandLine() API.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683156(v=vs.85).aspx

To convert the command line to an argv style array of strings, call the CommandLineToArgvW() function.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx
Thanks. But I notice the latter has 'W', which usually means Unicode... so will this still work with glutInit, since it expects a char** rather than a WCHAR**?
Use WideCharToMultiByte() function if you really need to convert between UTF-16 and local encodings.
Moreover, CommandLineToArgvW requires using GetCommandLineW() too ...

Another alternative is to parse yourserlf the full command line string resulted from GetCommandLineA().
Topic archived. No new replies allowed.