   'CreateWindowEx' causes error when called from a class function?
  Hey again. I am posting regarding the same project I was working on yesterday, when I made a post. I am creating an OpenGL framework that I can use for my OpenGL projects, if you didn't know.Anyhow, I am creating a window like this in a class:BOOL CGLWindow::CreateGLWindow(LPCTSTR lpszClassName, LPCTSTR lpszTitle,   UINT nWidth/* = 640*/, UINT nHeight/* = 480*/, UINT nBpp/* = 16*/,   BOOL bFullscreen/* = FALSE*/) {// TODO: Create the OpenGL windowGLuint nPixelFormat; // Window's pixel formatWNDCLASS wndClass;   // Window class structureDWORD dwStyle, dwExStyle;   // Window's styles and extended stylesRECT wndRect;// Window's rectanglewndRect.left   = 0;  // Left sidewndRect.right  = nWidth;  // Right side (width)wndRect.top    = 0;  // Top sidewndRect.bottom = nHeight; // Bottom side (height)// Copy each variable to its corresponding class memberm_nWidth  = nWidth;    // Window widthm_nHeight = nHeight;   // Window heightm_nBpp    = nBpp; // Window bppm_bFullscreen = bFullscreen; // Copy fullscreen flag// Setup and register window classm_hInstance = GetModuleHandle(NULL);  // Get handle to application's instancewndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Class stylewndClass.lpfnWndProc = (WNDPROC) glWndProc;// Wnd. proc. functionwndClass.cbClsExtra = 0;   // No extra class datawndClass.cbWndExtra = 0;   // No extra window datawndClass.hInstance = m_hInstance;    // Set app. instance handlewndClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);// Set default iconwndClass.hCursor = LoadCursor(NULL, IDC_ARROW);   // Set default cursorwndClass.hbrBackground = NULL;// No background (OGL does not require it)wndClass.lpszMenuName = NULL; // No menuwndClass.lpszClassName = lpszClassName;    // Window's class nameif (! RegisterClass(&wndClass))// Register the window class (from 'wndClass' object){// Display error message and return errorMessageBox(NULL, "Error registering window class in 'CGLWindow::CreateGLWindow'...\n", NULL, NULL);return FALSE;}// Check for fullscreen modeif (bFullscreen) // Go fullscreen{DEVMODE dmScreen; // Screen settingsmemset(&dmScreen, 0, sizeof(dmScreen));// Make sure memory is cleared// Setup members of 'dmScreen'dmScreen.dmSize = sizeof(dmScreen);   // Set memory sizedmScreen.dmPelsWidth  = nWidth;// Set widthdmScreen.dmPelsHeight = nHeight;    // Set heightdmScreen.dmBitsPerPel = nBpp;  // Set bits-per-pixeldmScreen.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;   // Set flags for use// Try to switch to desired fullscreen modeif (ChangeDisplaySettings(&dmScreen, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {if (MessageBox(NULL, "Fullscreen mode could not initialize.\nWould you like to use windowed mode?\n", "Error", MB_YESNO | MB_ICONQUESTION) == IDYES)    // Prompt for windowed mode{m_bFullscreen = FALSE;// Switch to windowed mode}else// Exit the application (fullscreen could not switch and user did not want windowed mode)return FALSE;// Return on error}}// Check for fullscreen modeif (m_bFullscreen)    // Are we in fullscreen mode?{dwExStyle = WS_EX_APPWINDOW;// Set window ext. styledwStyle   = WS_POPUP;  // Set window styleShowCursor(FALSE); // Hide the cursor}else // Windowed mode{dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;    // Set window ext. styledwStyle   = WS_OVERLAPPEDWINDOW;    // Set window style}AdjustWindowRectEx(&wndRect, dwStyle, FALSE, dwExStyle);// Adjust window's rect.// Attempt to create the window itself using 'CreateWindowEx'if (! (m_hWnd = CreateWindowEx(dwExStyle,   // Window's extended style  lpszClassName,    // Window's class name   lpszTitle,   // Window's title   WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle,    // Set window style   0, 0,    // Window position (top-left corner)   wndRect.right - wndRect.left,// Adjusted window width   wndRect.bottom - wndRect.top,// Adjusted window height   NULL, // No parent window   NULL, // No menu   m_hInstance,   // Application instance handle   NULL)))// Don't pass anything to 'WM_CREATE' message{// Kill the window, display error message, and return an errorchar szError[256];sprintf(szError, "Last Error: %d", GetLastError());KillWindow();// Kill the window (and anything else that was already initialized)MessageBox(NULL, "Error in 'CreateWindowEx' in function 'CGLWindow::CreateGLWindow'...\n", NULL, NULL);MessageBox(NULL, szError, NULL, NULL);return FALSE;}// Setup a pixel format descriptorstatic PIXELFORMATDESCRIPTOR pfd = {sizeof(PIXELFORMATDESCRIPTOR),  // Set size of 'pfd' object1, // Version numberPFD_DRAW_TO_WINDOW | // Format must support windowPFD_SUPPORT_OPENGL | // Format must support OpenGLPFD_DOUBLEBUFFER |   // Format must support double-bufferingPFD_TYPE_RGBA,  // Request RGBA formatnBpp, // Select specified color depth (bpp)0, 0, 0, 0, 0, 0,    // Ignore the color bits0,    // No alpha buffer0,    // Shift bit ignored0,    // No accumulation buffer0, 0, 0, 0,// Accumulation bits ignored16,   // 16-bit depth (Z) buffer0, 0, // No stencil or auxiliary bufferPFD_MAIN_PLANE, // Main drawing layer0,    // Reserved (ignore)0, 0, 0    // Layer masks ignored};// Attempt to get device context for windowif (! (m_hDC = GetDC(m_hWnd))) {// Kill the window, display error message, and return an errorKillWindow(); // Kill the windowMessageBox(NULL, "Error creating Device Context in function 'CGLWindow::CreateGLWindow'...\n", NULL, NULL);return FALSE;}// Attempt to select the pixel format (from 'pfd' object)if (! (nPixelFormat = ChoosePixelFormat(m_hDC, &pfd))) {// Kill the window, display error message, and return an errorKillWindow(); // Kill the windowMessageBox(NULL, "Error in 'ChoosePixelFormat' in function 'CGLWindow::CreateGLWindow'...\n", NULL, NULL);return FALSE;}// Attempt to set the pixel format for the screenif (! SetPixelFormat(m_hDC, nPixelFormat, &pfd)) {// Kill the window, display error message, and return an errorKillWindow(); // Kill the windowMessageBox(NULL, "Error in 'SetPixelFormat' in function 'CGLWindow::CreateGLWindow'...\n", NULL, NULL);return FALSE;}// Attempt to create an OpenGL rendering contextif (! (m_hRC = wglCreateContext(m_hDC))) {// Kill the window, display error message, and return an errorKillWindow(); // Kill the windowMessageBox(NULL, "Error creating GLRC in function 'CGLWindow::CreateGLWindow'...\n", NULL, NULL);return FALSE;}// Attempt to activate the rcif (! wglMakeCurrent(m_hDC, m_hRC)) {// Kill the window, display error message, and return an errorKillWindow(); // Kill the windowMessageBox(NULL, "Error activating 'm_hRC' in function 'CGLWindow::CreateGLWindow'...\n", NULL, NULL);return FALSE;}ShowWindow(m_hWnd, SW_SHOW);   // Show the windowSetForegroundWindow(m_hWnd);   // Set window as foreground windowSetFocus(m_hWnd);    // Set focus to this windowResizeScene(m_nWidth, m_nHeight);   // Resize the GL scene to the window// Attempt to initialize OpenGLif (! InitGL()) {// Kill the window, display error message, and return an errorKillWindow(); // Kill the windowMessageBox(NULL, "Error initializing OpenGL in function 'CGLWindow::InitGL'...\n", NULL, NULL);return FALSE;}return TRUE;    // Successful; return okay}The call to 'CreateWindowEx' fails, and displays "Last Error: 87". I used the 'Error Lookup' tool, and it says "The parameter is incorrect."Why is this happening? I have never had a problem creating a window before, and it only does this when called from a class function. It has nothing to do with any of the other functions that are called in 'CreateGLWindow'. It successfully registers the window class, and everything between 'RegisterClass' and 'CreateWindowEx' succeeds.Can anyone tell me why this is happening? I am using MSVC++ 6.0 on Win98.   
  When you call the function, are you sure you are passing a valid class name and a valid title?   ;  Yes, I am sure. =(   ;  Some windows styles and extended styles might be incompatible with each other.  That be my first course of investigation:  looking up the styles that you use in the documentation to see if there are any conflicts.  I know WS_POPUP has some restrictions; don't know if WS_EX_APPWINDOW is one of them.   ;  Well, I don't think that's the problem. And I just tried altering it, and it's the same thing. I used the NeHe base code as an example for my code. And I'm not using 'WS_POPUP' because I am first testing it in windowed mode. I only specify the 'WS_POPUP' style when I go fullscreen (as does NeHe).   ;  Does anyone else have any suggestions. I don't understand why 'CreateWindow(Ex)' works until I call it from a class function. If I create a standard Win32 app., it works just fine. But somehow, I am passing an invalid parameter (as told by error # '87'). Anyone else?   ;  How is glWndProc declared?   ;  In the 'CGLWindow' class:static LRESULT CALLBACK glWndProc(CGLWindow *pGLWnd, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);    // Default wnd. proc. (overrideable)I had to declare it static, because if I didn't, I would get an error. Does that help any? =)   ;  At the first glance I can see you're using WNDCLASS for CreateWindowEx (), what does that mean ?.[smile]This should cause an unhandled exception...   ;  Try passing the application instance to the function instead of using GetModuleHandle() to make sure that ur getting the right application instance, just a guess.   