Jump to content
  • Advertisement
Sign in to follow this  
dragonknightx

Windows Wrapper class problem

This topic is 5396 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a Windows wrapper class, and I have almost everything in it working (I think), but I also have a major problem: when building the class (before calling RegisterClass), I can't seem to get it to set lpfnWndProc to my WndProc. The essential parts:

LRESULT CWindow::WindowProc(UINT Msg, WPARAM wParam, LPARAM lParam)
{
// Function body
}

bool CWindow::BuildWindow()
{ WNDCLASSEX WndCls;
	WndCls.cbSize = sizeof(WndCls);
	WndCls.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	WndCls.lpfnWndProc = CWindow::WindowProc; // This is causing the problem.
	WndCls.cbClsExtra = 0;
	WndCls.cbWndExtra = 0;
	WndCls.hInstance = CWindow::m_hInstance;
	WndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	WndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
	WndCls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	WndCls.lpszMenuName = NULL;
	WndCls.lpszClassName = "MainWindowClass";
	WndCls.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
}

(Never used the tags before, so I hope they work - a 'Preview' option would be nice...) I've tried all manner of solutions, but I apparently haven't tried the right one yet. Any tips?

Share this post


Link to post
Share on other sites
Advertisement
It's a signature mismatch. The window procedure needs to be __stdcall, but your CWindow::WindowProc is of the __thiscall convention. You need to make it a static method to convert it, but that dissociates it from the CWindow instance.

Since I'm sure none of that made sense to you (which means that you need to read a lot more), read this article. And get into the habit of searching before posting; the web is littered with window class wrapper examples and tutorials.

Share this post


Link to post
Share on other sites
Thanks for the reply. I ran across that error a few times in my many trials, and while I could make a bit of sense out of it (I knew it was specifying THIS call, which was somehow different from the STANDARD call), I didn't have a clue how to fix it, so I moved on.

BTW, how do I get to that page (through the site - I obviously have the URL, and it looks like exactly what I need); something tells me I'm hardly using this site to its fullest, and I'd like to change that.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!