Window Class calling virtual child WndProc

Hey guys,

So I'm having this strange issue that I can't seem to resolve. I have two classes, a Window class and its base class, Control. Control is friends with the global WndProc() method and it basically manages what control or window child procedure, aka _wndproc, is to be called. This works fine for the most part, until I make it virtual. If I make just the base class Control virtual, the _wndproc hangs and the window is unusable. If I make both classes virtual, I get a runtime "access violation" error.

If you require more information, take a look at: http://www.uta.fi/~jl/pguibook/api2oo.html#simple
Toward the bottom is a zip. I used pretty much the same method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
LRESULT Control::WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{

	Control* ptr = NULL;

	if (msg == WM_CREATE) {

		LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lp;
		ptr = (Control*)lpcs->lpCreateParams;
		SetWindowLong(hwnd, 0, (LONG_PTR)ptr);

	}
	else
	ptr = (Control*) GetWindowLong(hwnd, 0);

	if (ptr)
		return ptr->_wndproc(msg, wp, lp); //Error/hang occurs here.
	else
	return DefWindowProc(hwnd, msg, wp, lp);

}


Any suggestions/ideas would be greatly appreciated. Thanks!
Ok, after much debugging and tweaking I have discovered that this problem has to do with the local HINSTANCE variable in the Window class. There was a case where the variable was not yet initialized and the procedure was called anyways resulting in a runtime error.
Topic archived. No new replies allowed.