tags:

views:

154

answers:

2

I'm trying to create a GL context, and the call fails, returning a null pointer. According to MSDN, when wglCreateContext fails, you get the reason why from GetLastError. Except that GetLastError gives me a number, which isn't all that informative.

Again according to MSDN, you can get a descriptive string out of the GetLastError code with FormatMessage. But when I try the following, I get a blank string:

FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), 0, errorStr, 0, NULL);

I checked the MSDN documentation, and apparently it only has a lookup table for Windows system errors. So that's no help to me afterall. Does anyone know how to figure out programmatically why my wglCreateContext call is failing?

A: 

I've found this MSDN page and this OpenGL page, but they only has the list of error code names, not their numerical values.

This page in the OpenGL reference mentions a function gluErrorString with this profile:

constGLubyte *gluErrorString(GLenum error)

Is this available in the library you're using? This should be defined in a file called "glu.h". For Visual Studio 6 it was in:

C:\Program Files\Microsoft Visual Studio\VC98\Include\GL

If you don't have that version it should be in:

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl

This folder should also contain "gl.h" which contains the definitions for the error codes.

EDIT If you're getting a null string that that might mean that it's a non standard error code. Get the value coming out of GetLastError() and search for it's hex representation in "gl.h". If it finds it then the define will tell you what the error is.

ChrisF
Tried that, but it also returns a null string.
Mason Wheeler
A: 

I found the problem. FormatMessage works just fine; I just had the wrong parameters. This worked:

FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), 0, errorStr, 255, NULL);
Mason Wheeler