opengl function CreateWindowEx exits

Jul 26, 2011 at 2:22am
Environment: Windows 7, 64 bit, Visual Studio, Console application, C++
I am following the openglbook.com and this web page:
http://openglbook.com/the-book/chapter-1-getting-started/
After entering the program for Chapter1.c the program shows the DOS window then closes it and disappears. Using the debugger I stepped down into file: freeglut_window.c and the following function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void fgOpenWindow( SFG_Window* window, const char* title,
                   GLboolean positionUse, int x, int y,
                   GLboolean sizeUse, int w, int h,
                   GLboolean gameMode, GLboolean isSubWindow )
{
#if defined(_WIN32_WCE)#else
    window->Window.Handle = CreateWindowEx(
        exFlags,                            // = 0
        _T("FREEGLUT"),
        title,                              // = “Chapter 1”
        flags,                              // = 382664704
        x,                                  // = 0x08000 0000
        y,                                  // = 0x08000 0000
        w, h,                               // w = 816, h = 638
        (HWND) window->Parent == NULL ?     // window_Parent == NULL
                 NULL :                     // must be selecting this option
                 window->Parent->Window.Handle,
        (HMENU) NULL,
        fgDisplay.Instance,                 // 0x00fc0000
        (LPVOID) window                     // 0x00771290
    );
#endif 


When the code gets to this CreateWindowEx function, I try to step in. The program brings the DOS window to the front, then exits. Its just gone. How can I determine the problem? What should I do different?
Thanks for your time.
Jul 26, 2011 at 2:36am
I haven't checked your flags, etc values for sanity, but are you sure that you aren't using uninitialized pieces of the window structure inside your window proc on the WM_CREATE message?

If this isn't the case, add code to check that the window->Window.Handle is not NULL. If it is, you need to call GetLastError() to find out what went wrong.

BTW, CreateWindowEx() is not an OpenGL function, it is a Windows API function. Google "msdn createwindowex" for more.

Hope this helps.
Jul 27, 2011 at 12:06am
All the calls leading up to the method that winds up here return 0 for GetLastError. This function returns window->Window.Handle. Having it NULL here should be expected. This call is the one that produces that handle. The is no return value, does not return. The program quits before the call is complete.

Ok, its a windows API function. Is there a reason whey OpenGL should not call this function? The code gets here from the line:
WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);

All the previous lines in InitWindow produce 0 (zero) for GetLastError();

The output window of VS showns:
The thread 'Win32 Thread' (0xf0c) has exited with code 1 (0x1).
The program '[3752] OpenGL_V01.exe: Native' has exited with code 1 (0x1).

Indicating an error. But again, when stepping into or over this function call, Visual Studio never gets to the next line of code. The program just quits.
Aug 4, 2011 at 1:17am
The problem is resolved. My video adapter was an on the motherboard board chip of ATI Radeon 4000 vintage. I installed an ATI Rddeon HD 5670 and the code runs. Nothing to the installation. I installed their software then allowed it to get upgrades. If ran right away with no problems.
Thanks to all who posted.
Topic archived. No new replies allowed.