Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trouble passing class function to variable of its prototype.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Im having trouble with compiling this piece of code. Ive cut out the irrelevant stuff

class DWND
{
public:
//constructor
DWND(<parameters>)
{
WNDCLASSEX wcx;
wcx.lpfnWndProc = this->MainWndProc; //problem line
}

LRESULT CALLBACK MainWndProc(<parameters>)
{
blah blah
}
}

The problem is that the compiler complains that it cant convert from:
long (__stdcall DWND::*)(<parameters>)
to
long (__stdcall *)(<parameters>)

It compiles properly if the MainWndProc function isnt a member of a class but when it is, the compiler tries to include the DWND:: in front of it and complains that it doesnt match the definition of the lpfnWndProc member of the WNDCLASSEX structure.
I dont know how to make the compiler ignore the DWND:: before it. Anyone know how I can do this? or isnt it possible?
Also, how should the subject title of this message have been written? I spent about 10 minutes trying to figure what order to put all those words and I still dont know.
 
the ; is there in the code. It must have dropped off when I copied the code to the post.

The problem is:
wcx.lpfnWndProc = this->MainWndProc;

The compiler gets annoyed because the definition of lpfnWndProc is a function but it doesnt like passing the correct function to it if its a member of a class.

I could get round it by changing the definition of lpfnWndProc in windows.h or wherever it is, but thats nasty and there should be an easier way of doing it.



 
Hello Friend,
What you r doing is invalid cast..see the function to wcx.lpfnwndproc required is different .Do onw thing make the function MainWndProc Global and not the part of your class ok...this will solve your problem and then you should learn the function signatures and you will come to know your mistake..

Have fun
Krishna
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top