Thread: more static/class problems

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    more static/class bastardry

    ok, now im angry. something that worked a second ago stopped working. ken, i know you'll read this post so i wont post much detail.

    Code:
    LRESULT CALLBACK cEdit::cEditProcA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    	cEdit *ce;
    
    	if (msg!=WM_NCCREATE)
    	{
    		ce=(cEdit *)GetWindowLong(hwnd,GWL_USERDATA);
    		return CallWindowProc(ce->cEditProc,hwnd,msg,wParam,lParam);
    	}
    
    switch (msg)
    	{
    	case WM_NCCREATE:
    		LPCREATESTRUCT lpc;
    		cEdit *tmpCE;
    		
    		lpc=(LPCREATESTRUCT)lParam;
    		SetWindowLong(hwnd,GWL_USERDATA,(LONG)lpc->lpCreateParams);
    		tmpCE=(cEdit *)GetWindowLong(hwnd,GWL_USERDATA);
    		return CallWindowProc(tmpCE->wpProc,hwnd,msg,wParam,lParam);
    thats the start static wndproc, it calls a normal wndproc. on the callwindowproc that dereferences ce, it tells me it cant convert parameter 1 from 'long (struct HWND__ *,unsigned int,unsigned int,long)' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'. it doesn't happen for tmpCE, even though it is exactly the same code. whats wrong here?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    return CallWindowProc(tmpCE->wpProc,hwnd,msg,wParam,lParam);
    You are trying to pass this::Wndproc as a parameter that wants a WNDPROC.

    Either you have a global or static WNDPROC variable to store the old one (not advised), or have a class scope WNDPROC variable for storage.

    That's why you have a virtual wndproc: to forward the messages to from your static one. All the static one has to do is resolve this and then use it to pass the message and its parameters to your virtual class wndproc ie:
    Code:
    tmpCE=(cEdit *)GetWindowLong(hwnd,GWL_USERDATA);
    tmpCE->MyMsgProc(msg,wParam,lParam);
    where MyMsgProc is your virtual wndproc (you could also pass the handle if you want).

    Now in the body of your C++ class wndproc, using the c++ class scope WNDPROC as discussed above you can safely use CallWindowProc, giving it what it wants ie:
    Code:
    CallWindowProc(OldWndProc,hwnd,msg,wParam,lParam);
    where OldWndProc is a (preferrably private) WNDPROC variable of your c++ class.

    BTW, it would be better to keep all the relevant stuff relating to this in one thread rather than spamming the board with '1001 ways to beast my window procedure'.
    Last edited by Ken Fitlike; 01-04-2003 at 08:14 PM.

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    ok, from now on, if i have any class related questions ill create one thread and only post there. so heres the last post for this thread: in that last problem i had, why was tmpCE different from ce? i did what you said, and it worked, but id still like to know why only one of the callwindowprocs caused an error.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>but id still like to know why only one of the callwindowprocs caused an error.<<

    'wpProc' wouldn't be a global or static wndproc having the same type as a WNDPROC, would it? And 'cEditProc', is it a normal c++ class function?

    If not that then maybe msvc++ just reported the first 'unresolved' it encountered; if you change just the first one as suggested and rebuild, would it issue the same type of 'unresolved' error msg regarding the second CallWindowProc?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM