Thread: CreateWindowEx causes either ERROR_INVALID_PARAMETER or ERROR_INVALID_WINDOW_HANDLE.

  1. #1
    Registered User
    Join Date
    Sep 2019
    Posts
    5

    Question CreateWindowEx causes either ERROR_INVALID_PARAMETER or ERROR_INVALID_WINDOW_HANDLE.

    I'm learning the Win32 framework (and others) to make a simple window to later draw with OpenGL on (C99).
    Code:
    WNDCLASSEX wc = {
        .cbSize = sizeof(WNDCLASSEX),
        .style = 0,
        .lpfnWndProc = cif_win32_wndproc,
        .cbClsExtra = 0,
        .cbWndExtra = 0,
        .hInstance = GetModuleHandle(NULL),
        .hIcon = LoadIcon(NULL, IDI_APPLICATION),
        .hCursor = LoadCursor(NULL, IDC_ARROW),
        .hbrBackground = (HBRUSH) (COLOR_WINDOW + 1),
        .lpszMenuName = NULL,
        .lpszClassName = cif_win32_class,
        .hIconSm = LoadIcon(NULL, IDI_APPLICATION),
    };
    
    if(!RegisterClassEx(&wc)) {
        return NULL;
    }
    
    HWND hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, cif_win32_class, "Nyeeh", WS_EX_OVERLAPPEDWINDOW, 200, 200, 240, 120, NULL, NULL, GetModuleHandle(NULL), NULL);
    `cif_win32_class` is just a `const char[]`.

    Here `CreateWindowEx` gives me an 1400 error (`ERROR_INVALID_WINDOW_HANDLE`). Strangely, if I replace `"Nyeeh"` with `""`, then I get an 87 error instead (`ERROR_INVALID_PARAMETER`).

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Works just fine for me. You're probably passing the wrong window handle to DefWindowProc inside cif_win32_wndproc.

    In an unrelated note, since you're using the portable OpenGL, I'd suggest not limiting yourself on a single OS. Libraries such as SDL2 mix with OpenGL quite well, and make your program multi-platform without any extra effort.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Sep 2019
    Posts
    5
    That was indeed it, thank you for your help.

    Quote Originally Posted by GReaper View Post
    In an unrelated note, since you're using the portable OpenGL, I'd suggest not limiting yourself on a single OS. Libraries such as SDL2 mix with OpenGL quite well, and make your program multi-platform without any extra effort.
    Actually, as I said I'm building multiple backends as I'm creating an SDL2 alternative for myself. SDL1 as far as I know is not supported anymore and it ended up being easier to remake certain things while also supporting more than just the three major systems. Sounds stupid, but I like to build things myself even if it takes a bit more time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CreateWindowEx() failing with 64-bit
    By domokato in forum Windows Programming
    Replies: 7
    Last Post: 07-02-2009, 07:30 PM
  2. Win32 CreateWindowEx
    By Raigne in forum Windows Programming
    Replies: 5
    Last Post: 06-27-2006, 07:10 AM
  3. CreateWindowEx - GetLastError() = 6
    By cboard_member in forum Windows Programming
    Replies: 9
    Last Post: 04-20-2006, 08:29 AM
  4. Having Trouble with CreateWindowEx
    By Eber Kain in forum Windows Programming
    Replies: 10
    Last Post: 06-05-2004, 07:45 AM
  5. CreateWindowEx(...) help
    By Dohojar in forum Windows Programming
    Replies: 4
    Last Post: 03-02-2003, 02:33 PM

Tags for this Thread