Nehe Window Base Code Error

When I try to compile NeHe’s base code I get an error on the line:

wc.lpfnWndProc = (WNDPROC) WndProc;

The error is the following:

‘type cast’ : cannot convert from ‘’ to ‘long (stdcall *)(struct HWND *,unsigned int,unsigned int,long)’

and then says:
None of the functions with this name in scope match the target type

Can someone help me?

What compiler (and compiler version) are you using?

Visual C++ 6.0 with SP2

And it does this without having been modified in any way?

[This message has been edited by DFrey (edited 02-05-2001).]

No, I am trying to make a window creation class. I simply put what NeHe had as global variables in as private variables in the class, and then I put the different functions he had as public functions of the class.

Did you also attempt to make WndProc a member of that class? Because that won’t work.

I have got it as a member of the class. Why wouldn’t that work?(As a knowledge gain) And how can I fix it?

Because when it is the member of a class, it is at a different scope, and has a calling convention that is different from __stdcall.
You’ll need to have that function as a non-member, or at most a friend of the class.

Or make it a static member function.

Oh yes, or make it a static member function. I totally forgot about that option (obviously).

Okay, you left my knowledge scope. I know what a friend function is and will try that shortly but would you mind telling me what a static member function is?

Without getting too technical, a static function is one that is used for every instance of your class. (Therefore a pointer to it will be the same for every instance of your class) I’ll use a static member variable as an example because it’s a bit easier to understand. Say you have a static int m_num in a class Blah; If you were do to this…

Blah a, b;

a.m_num = 10;

if (b.m_num == 10)
{
// this’ll be true…
b.m_num = 5;
// now a.m_num == 5
}

You can only access other static members from within a static function. With functions it more to do with the pointer functions in the vtable. If you don’t know what a vtable is, don’t worry about it. Just realize that static functions can only access static members. (But non-static functions CAN access static members.)

Another quirk of static functions is that you can call them w/o instantiating a class… say you had a static SomeFunc() in class Blah. You could call it like so…

Blah::SomeFunc();

Thank you. The static membership did it! Now I just have to debug it. Thanks again!!!