WNDCLASS and class

This is a discussion on WNDCLASS and class within the C++ Programming forums, part of the General Programming Boards category; I have the following code: class XXX { LRESULT CALLBACK mywndproc(HWND, UINT, LPARAM, WPARAM); // or WPARAM, LPARAM, doesn't matter ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    244

    Angry WNDCLASS and class

    I have the following code:

    class XXX {
    LRESULT CALLBACK mywndproc(HWND, UINT, LPARAM, WPARAM); // or WPARAM, LPARAM, doesn't matter

    short createawindow();
    };


    short XXX::createawindow()
    {
    WNDCLASS wndclass;
    ...
    wndclass.lpfnWndProc = mywindowproc; //!!!

    return 0;
    }

    LRESULT CALLBACK XXX::mywndproc(args...)
    {
    code
    }

    so, what's wrong with the line marked with the !!!s?

    Why do I get the error msg:
    can't convert whatever(__stdcall XXX::*)whaterver to whatever whatever?
    I mean, I know that the conversion is invalid, but I still want to use the callback function within my class.

  2. #2
    Quietly Lurking
    Join Date
    Aug 2001
    Posts
    208

    Wink

    this might just be a typo that you did when you posted to the board but I dont see what else would be wrong so could it be that

    wndclass.lpfnWndProc = mywindowproc; //!!! -- should be wndclass.lpfnWndProc = mywndproc;

    since both the prototype and function header are called wndproc not windowproc

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    244

    Thumbs down

    nope, that's not the problem,
    of course i ment mywndproc!
    just a typo.

    btw, my real code doesn't look that way, this is just a short "briefing" that leads to the problem i have.

    the problem is because of the class.
    as I said the error message is:

    cant convert (something)(__stdcall XXX::*)(something) to (something)(something)

    so the only difference between the two types is the (__stdcall XXX::*)

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Your compiler may be picky about what you are doing here. Try adding changing short createawindow() to short createawindow(void) and changing short XXX::createwindow() to short XXX::createwindow(void). If this doesn't work then I don't know what will.

  5. #5
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128

    Impossible conversion

    class XXX {
    LRESULT CALLBACK mywndproc(HWND, UINT, LPARAM, WPARAM); // or WPARAM, LPARAM, doesn't matter
    short createawindow();
    };
    short XXX::createawindow()
    {
    WNDCLASS wndclass;
    ...
    wndclass.lpfnWndProc = mywindowproc; //!!!
    The method is seen by the compiler as :
    mywndproc(XXX* const this,HWND,UINT,WPARAM,LPARAM);
    // the wParam should come first
    so it can't convert the pointer, since it's declared to point to a function of proto :
    func(HWND,UINT,WPARAM,LPARAM);

    If you'd like to declare a pointer to your method, you'd do :
    typedef LRESULT (XXX::*pfnMyMethod_t)(HWND,UINT,WPARAM,LPARAM);

    and then : pfnMyMethod_t pfnProc = XXX_Instance.mywindowproc;

  6. #6
    Unregistered
    Guest
    Hi
    The types of the lpfnWndProc member of the WNDCLASS struct and your method of the class XXX are not the same.
    Just each non-static method of the class has a 'hidden' first argument which value is used as 'this' - actually a pionter to the instance of the class(real object). so the above two types are not the same - just they looking the same.

    Workaround of your problem may be to use the SetWindowLong
    to set the ponter to the instance of the class (this), as a long value in the window's extra bytes, declare the static method and set it to the lpfnWindowProc member of the WNDCLASS struct when the window is created and then just to re-route the arguments to the desired function of the object which 'this' is in the extra window bytes.

  7. #7
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128

    Unhappy I made a mistake

    pfnMyMethod_t pfnProc = XXX_Instance.mywindowproc;
    I think this should be :
    Code:
    pfnMyMethod_t pfnProc = &XXX::mywindowproc;
    and then call it :
    Code:
    (XXX_Instance.*pfnProc)(hWnd,wMsg,wParam,lParam);
    Sorry for the inconvenience

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my Class??
    By salman86 in forum Windows Programming
    Replies: 1
    Last Post: 07-12-2005, 12:08 AM
  2. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 03:33 PM
  3. Skeleton Window: Message Handler in a Class?
    By Epo in forum Windows Programming
    Replies: 8
    Last Post: 12-29-2003, 03:30 PM
  4. Wndclassex And Wndclass
    By rip1968 in forum Windows Programming
    Replies: 3
    Last Post: 03-15-2003, 11:47 AM
  5. Difficulty superclassing EDIT window class
    By cDir in forum Windows Programming
    Replies: 7
    Last Post: 02-21-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21