You never assign to gInstance
and so it is default initialised to NULL
. You then pass that to DialogBox
.
Assign hInstance
to gInstance
in WinMain
.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
gInstance = hInstance;
DialogBox(gInstance, MAKEINTRESOURCE(IDD_DIALOG), hwnd, WndProc);
return TRUE;
}
Or just do away with gInstance
altogether since you don't use it anywhere else. Delete the variable and make your WinMain
like this:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), hwnd, WndProc);
return TRUE;
}
There is more code that you are omitting though because I cannot see the declaration or initialisation of hwnd
. It's always best to show a complete SSCCE if possible, and it's clearly possible here.
And also take heed of Raymond's comment to the question and move the call to InitCommonControls into WinMain.