Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <windows.h>
#include <winuser.h>

LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int nCmdshow) 
{
    WNDCLASSW wc;

    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hInstance = hInst;
    wc.lpszClassName = L"myWindowClass";
    wc.lpfnWndProc = WindowProcedure;
    RegisterClass(&wc);
    return 0;
    CreateWindowW(L"myWindowClass", L"My Window", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 500, 500, NULL, NULL, NULL, NULL);
		
    return 0;
}

LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
}


What I have tried:

I tried the above code. I am trying to get it to work.
Posted
Updated 22-Apr-20 10:09am
v2

You forgot the message pump in your WinMain

C++
while ( GetMessage(&msg, NULL, 0, 0) )
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}
return msg.wParam;


and in your WindowProcedure you forgot the return value

C++
return DefWindowProc(hWnd, message, wParam, lParam);


WinMain does not return until window is destroyed
 
Share this answer
 
v3
It appears to me you have excessive return statements. Increase the warning level on your compiler so it will tell you about that. You should have received a warning because the CreateWindow call is unreachable.

Remove the first return 0 statement so you have just one at the end of the function.

-edit- that is not the exact cause of your error but searching for "inconsistent annotation winmain" will give you lots of hints.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900