Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7668993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:29:45+00:00 2026-05-31T15:29:45+00:00

I am getting the error ERROR_INVALID_WINDOW_HANDLE when CreateWindowEx() fails in my program. I am

  • 0

I am getting the error ERROR_INVALID_WINDOW_HANDLE when CreateWindowEx() fails in my program. I am using C++ with the native Win32 API.

I have no idea why, and I have tried toying with some parameters in CreateWindowEx but it still produces the exact same error every time.

I have also tried adding W to random functions and data types hoping that the UNICODE version somehow works…nothing changed, of course.

This is the function that calls CreateWindowEx():

int InitMainWindow( HWND *hwnd, WNDCLASSEXW *wnd, WNDPROC wndproc )
{
    memset( wnd, NULL, sizeof( WNDCLASSEXW ) );
    wnd->cbSize = sizeof( WNDCLASSEXW );
    wnd->lpszClassName = L"MainWClass";
    wnd->lpfnWndProc = wndproc;
    wnd->hInstance = GetModuleHandle( NULL );

    if( NULL == RegisterClassExW(wnd) )
    {
        printf( "InitMainWindow::RegisterClassexW() error: %d\r\n", GetLastError() );
        return GetLastError();
    }

    *hwnd = CreateWindowExW
        (
        WS_EX_ACCEPTFILES | WS_EX_APPWINDOW, //extended styles
        wnd->lpszClassName, //class name
        L"MainWindow", //window name
        WS_OVERLAPPEDWINDOW | WS_VISIBLE, //style tags
        CW_USEDEFAULT, //horizontal position
        CW_USEDEFAULT, //vertical position
        900, //width
        600, //height
        GetDesktopWindow(), //parent window
        NULL, //class menu
        GetModuleHandle(NULL), //some HINSTANCE pointer
        NULL //Create Window Data?
        );

    if( NULL == *hwnd )
    {
        printf( "InitMainWindow::CreateWindowEx() error: %d\r\n", GetLastError() );
        return GetLastError();
    }

    return 0;
}

This is the main method:

static HWND mainhwnd;
void main()
{
    DWORD time;
    time = GetTickCount();

    MSG msg;
    WNDCLASSEXW wnd = { 0 };
    NOTIFYICONDATA nid;

    InitMainWindow( &mainhwnd, &wnd, MainWndProc );
    InitNotifyIcon( &mainhwnd, &nid );
    ShowWindow( mainhwnd, true );
    UpdateWindow( mainhwnd );

    time = ( GetTickCount() - time );
    std::cout << "Time: " << time << "\r\n" << std::endl;

    for( ; ; ) //message loop
    {
        while( GetMessage( &msg, NULL, 0, 0 ) )
        {
            if( WM_CLOSE == msg.message ) //reassign close button to minimize to tray
            {
                printf("close\r\n");
                break;
            }

            TranslateMessage(&msg);
            DispatchMessage(&msg);

            /*if( !IsDialogMessage( hwndListDialog, &msg ) )
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }*/
        }
        Sleep( 5 );
    }
}

This is my Windows Procedure:

LRESULT CALLBACK MainWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    switch(uMsg)
    {
    case WM_CREATE:
        printf("Main Window Create.......SUCCESS");
        break;
    default:
        break;
    }

    return DefWindowProc( mainhwnd, uMsg, wParam, lParam );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:29:46+00:00Added an answer on May 31, 2026 at 3:29 pm

    I think the problem is with your call to DefWindowProc.

    Try changing the line:

        return DefWindowProc( mainhwnd, uMsg, wParam, lParam );
    

    To this:

        return DefWindowProc( hwnd, uMsg, wParam, lParam );
    

    I’ve just compiled your code here with that change and it works OK.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried creating a named pipe but getting GLE 5 (access denied Error)
I'm getting the invalid lvalue error using gcc 3.4.6. The line that invokes the
I'm trying to compile some code, but I'm getting an error: Error invalid conversion
I have had some problems with getting GAE and Maven to work with each
I am getting a heap corruption error when trying to compile my program. The
I'm getting the error Invalid argument supplied for foreach() even though the array being
I'm getting this error: The remote certificate is invalid according to the validation procedure.
I am getting this error: Data at the root level is invalid. Line 1,
I keep on getting this error error: expected specifier-qualifier-list for core data code im
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.