Error 87 from RegisterClassEx()

This is a discussion on Error 87 from RegisterClassEx() within the Windows Programming forums, part of the Platform Specific Boards category; Hi I'm creating a game engine in openGL and first of all: please don't say that I should post this ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    92

    Error 87 from RegisterClassEx()

    Hi
    I'm creating a game engine in openGL and first of all: please don't say that I should post this somewhere else - it's the window creation that I got problems with so I think that it fits right in here.

    Anyway, I set a lot of parameters to a WNDCLASSEX variable and pass it on to RegisterClassEx(). Unfortunatly it returns 0 and gives the error message 87 (invalid parameter) from GetLastError. I have tried everything, including changing some parameters in the initWindowClass function but nothing seems to work, here is my code:

    Code:
    //Code in main.cpp - call for the class:
    wWindow mainWindow(WndProc, hInstance);
    	mainWindow.createGLWindow(className, windName, SCREEN_HEIGHT, SCREEN_WIDTH, 32);
    
    
    
    //code in init.h - declaration of the class:
    class wWindow
    {
    public:
    	wWindow(WNDPROC tWndProc, HINSTANCE hInst);
    	~wWindow();
    
    	HWND hwnd;
    	HINSTANCE hinstance;
    	HDC hdc;
    	WNDCLASSEX wndclass;
    	WNDPROC wndproc;
    	HGLRC hrc;
    	LPCSTR tclassName;
    	bool wWindow::createWindow(LPCSTR className, LPCSTR windowName,  LPCSTR menuName, int height, int width);
    	bool wWindow::createGLWindow(LPCSTR className, LPCSTR windowName, int height, int width, int bits);
    };
    
    
    
    //code in Init.cpp - which contains the class:
    wWindow::wWindow(WNDPROC tWndProc, HINSTANCE hInst)
    {
    	wndproc = tWndProc;
    	hdc = NULL;
    	hinstance = hInst;
    }
    
    
    bool wWindow::createGLWindow(LPCSTR className, LPCSTR windowName, int height, int width, int bits)
    {
    	wndclass = initWindowClass(className, hinstance, wndproc, NULL, NULL);
    	SetLastError(0);
    	DWORD eh = GetLastError();
    	RegisterClassEx(&wndclass);
    	eh = GetLastError();
    	hwnd = createWindowR(className, windowName, height, width, hwnd, hinstance);
    	hdc = GetDC(hwnd);
    
    	setPiFD(SCREEN_HEIGHT, SCREEN_WIDTH, 16, hdc);
        
        if (!(hrc = wglCreateContext(hdc)))
    	{
    		MessageBox(NULL, "Error creating hRC", "Error", NULL);
    	}
                
        wglMakeCurrent(hdc, hrc);
           
        initGL();
        
        ReSizeGLScene(SCREEN_WIDTH, SCREEN_HEIGHT);
        ShowWindow(hwnd, SW_SHOW);
        UpdateWindow(hwnd);
    	return true;
    }
    
    //The initWindowClass and createWindow functions:
    
    NDCLASSEX initWindowClass(LPCTSTR className, HINSTANCE hinst, WNDPROC wndproc, LPCTSTR menuName, HBRUSH backGround)
    {
    	WNDCLASSEX wndClass;
    
         wndClass.cbSize = sizeof(WNDCLASSEX);
         wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
         wndClass.lpfnWndProc = wndproc;
         wndClass.cbClsExtra = 0;
         wndClass.cbWndExtra = 0;
         wndClass.hInstance = hinst;
         wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
         wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
         wndClass.hbrBackground = backGround;
         wndClass.lpszMenuName = menuName;
         wndClass.lpszClassName = className;
    			 
         return wndClass;
    }
    
    HWND createWindowR(LPCTSTR className, LPCTSTR windName, int width, int height, HWND hwnd, HINSTANCE hinst)
    {
         
         hwnd = CreateWindowEx(         NULL,
                                        className,
                                        windName,
                                        WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW,
                                        0, 0,
                                        width, height,
                                        NULL,
                                        NULL,
                                        hinst,
                                        NULL);
         if (!hwnd)
         {
    		 MessageBox(NULL, "Error creating window", "ERROR", NULL);
            return NULL;  
            }
            return hwnd;
    }
    Help would be really appreciated -

    The Wazaa

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    WNDCLASSEX has an additional 'hIconSm' member.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    92
    Thanks a lot. Its working perfect now

    The Wazaa

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RegisterClassEx fails on Win95
    By knutso in forum Windows Programming
    Replies: 5
    Last Post: 01-20-2003, 08:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21