Cannot create window

Aug 5, 2012 at 4:26pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <Windows.h>
#include <stdlib.h>
#include <tchar.h>

#pragma comment(linker,"\"/manifestdependency:type='win32'name='Microsoft.Windows.Common-Controls'\
                version='6.0.0.0' processorArchitecture='*'\
                publicKeyToken='6595b64144ccf1df' language='*'\"")

LRESULT WINAPI WndProc(HWND hWnd,UINT msg,WPARAM lParam,LPARAM wParam)
{
	return DefWindowProc(hWnd,msg,wParam,lParam);
}

int WinMain(HINSTANCE hInst,HINSTANCE hpInst,LPSTR cmdLine,int cmdshow)
{
	static TCHAR classname[]=_T("SCONF");
	static TCHAR wTitle[]=_T("Server Configurator");
	
	WNDCLASSEX wClass;
	wClass.cbClsExtra=NULL;
	wClass.cbSize=sizeof(WNDCLASSEX);
	wClass.cbWndExtra=NULL;
	wClass.hbrBackground=(HBRUSH)(CTLCOLOR_SCROLLBAR);
	wClass.hCursor=LoadCursor(NULL,IDC_ARROW);
	wClass.hIcon=LoadIcon(hInst,IDI_APPLICATION);
	wClass.hIconSm=LoadIcon(hInst,IDI_APPLICATION);
	wClass.hInstance=hInst;
	wClass.lpfnWndProc=WndProc;
	wClass.lpszClassName=classname;
	wClass.lpszMenuName=NULL;
	wClass.style=CS_HREDRAW|CS_VREDRAW;
	if(!RegisterClassEx(&wClass))
	{
		MessageBox(NULL,L"Could not register class!", L"ERROR",MB_ICONERROR|MB_OK);
	}
	RECT wr={0,0,200,250};
	AdjustWindowRect(&wr,WS_CAPTION,false);
	
	HWND hWnd=CreateWindow(
		classname,
		wTitle,
		WS_CAPTION,
		GetSystemMetrics(SM_CXSCREEN)/2-100,
		GetSystemMetrics(SM_CYSCREEN)/2-125,
		wr.right-wr.left,//width
		wr.bottom-wr.top,//height
		NULL,
		NULL,
		hInst,
		NULL);

	if(!hWnd)
	{
		MessageBox(NULL,_T("Could not create window!"),_T("ERROR!"),MB_ICONERROR);
		return 1;
	}
	ShowWindow(hWnd,cmdshow);
	MSG msg;
	while(GetMessage(&msg,0,0,0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return (int)msg.wParam;
}


this is the full code, when I try to compile, the hWnd always returns false...I even tried copying the code from a working program and it did not work...What's going on here? It always worked before...
Aug 5, 2012 at 5:07pm
Use GetLastError() to see why it is failing.
Aug 5, 2012 at 5:20pm
That's odd...the error returned is 0...
Aug 5, 2012 at 5:47pm
It returns error code 126 for me.
ERROR_MOD_NOT_FOUND

126 (0x7E)

The specified module could not be found.

Aug 5, 2012 at 6:23pm
so what's wrong with it?
Aug 5, 2012 at 8:00pm
This is not helping.
1
2
3
4
LRESULT WINAPI WndProc(HWND hWnd,UINT msg,WPARAM lParam,LPARAM wParam) //check your parameter names!!!!!!!!!!!!!!!!!!!!!!!
{
	return DefWindowProc(hWnd,msg,wParam,lParam);
}
Aug 6, 2012 at 4:32am
See if adding WS_POPUP makes a difference.
Aug 6, 2012 at 6:03am
The WinMain calling convention must be changed to stdcall.
Aug 6, 2012 at 7:14am
I repeat, he is is twisting/crossing over his wParam and lParam in The WndProc function -

LRESULT WINAPI WndProc(HWND hWnd,UINT msg,WPARAM lParam,LPARAM wParam)
{
return DefWindowProc(hWnd,msg,wParam,lParam);
}

LRESULT WINAPI WndProc(HWND hWnd,UINT msg,WPARAM lParam,LPARAM wParam)
return DefWindowProc(hWnd,msg,wParam,lParam);
}
Aug 6, 2012 at 7:32am
guesthulkan was right xD
I can't believe I made a stupid mistake like that :P Problem solved.
Topic archived. No new replies allowed.