registering windowproc

Started by
5 comments, last by SCRUB 22 years, 3 months ago
Im having a simple problem that I cant seem to get aroudn Im trying to register my windows procedure function in my class. Ive basically ripped the nehe code and tried to put it into a class.
  
wc.lpfnWndProc		= (WNDPROC) (TemplateProc);		// TemplateProc Handles Messages

  
but I get a casting error that doesnt make much sence to me as everyhitng looks like it should be in place !!!
  
error C2440: ''type cast'' : cannot convert from '''' to ''long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)''
None of the functions with this name in scope match the target type
  
the TemplateProc is declared in my header and is how a WNDPROC should be declared !! i.e. LRESULT CALLBACK TemplateProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); cheers people
LE SCRUB
Advertisement
Is TemplateProc declared before this assignment occurs? Is TemplateProc either a global function or a static method? If one of your answers is "no", there''s your problem.

Others will post more suggestions shortly. While you''re at it, though, search these forums for threads on placing window procedures in classes (I use the search terms "Window handler class"). The search link is in the upper-right corner.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

the TemplateProc function is in my config class file, as is my createWindow function from which this error is generating.
Because its a Windows Procedure function its a callback function which makes it static (im nearly sure). But I dont see how it being static should stop it from compiling ?

Looking at it without the (WNDPROC) cast it says it cannot convert from ''long (__stdcall gconfig_t::*) (...)'' to ''long (__stdcall) (...)''.

hmmm casting is the only way I can think of around this (though im sure im wrong)
LE SCRUB
I ran into the same problem while trying to add the EnumDevices to a class and pass it to DirectX''s enumeration function. I believe a friend of mine got around it by making the function static, but I can''t be positive.
[xian]
Here is how I do it and it works fine:

static LRESULT CALLBACK WindowProc(HWND win, UINT msg, WPARAM wparam, LPARAM lparam); 


wc.lpfnWndProc = WindowProc; 
declaring a function as a CALLBACK just forces pascal parameter passing. It''s a different way of passing parameters on the stack and returning a value. You still have to declare the function as static if you want it to be static.
righto gots it.

thanking you all for your help.
LE SCRUB

This topic is closed to new replies.

Advertisement