Results 1 to 4 of 4

Thread: [RESOLVED]Callback Type Problem

  1. #1

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Resolved [RESOLVED]Callback Type Problem

    First off, I'm a newbie C++ coder, so I'm sorry if what I'm asking is obvious, but searching has given me no solution. I'm trying to write a simple window class with the message handler passed by the class user, so I define a member variable as "LRESULT(*)(HWND, UINT, WPARAM, LPARAM)", which is supposed to be the function pointer. Then I assign the passed value(same type) to this member, which results in the error: "invalid conversion from `LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)' to `LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)'". I read that it could be caused by the function address being that of a non-static member function, but I've tried both a normal function and a member, and both result in the same error.

    Here's the code that concerns this problem(it's scattered around a few files, but that's unimportant I think all are linked by inclusion):
    PHP Code:
    typedef LRESULT(*grCallbackWndProc)(HWNDUINTWPARAMLPARAM);

    LRESULT CALLBACK MessageHandler(HWND hWndUINT iMessageWPARAM wParamLPARAM lParam);

    grErrorCode grWindow::Create(HINSTANCE hInstance,
                           
    grCallbackWndProc WndProc,
                           
    LPSTR sTitle,
                           
    int iWidth,
                           
    int iHeight,
                           
    int iStyle) {
            if (
    == WndProc) {
                
    //This line gives the error.
                
    mWndProc = &MessageHandler;
            } else {
                
    mWndProc WndProc;
            }
            
    //Rest of code that compiles fine.

    This is using the GCC compiler.

    Thanks for any insight.
    Last edited by Max_aka_NOBODY; May 9th, 2006 at 07:59 AM.
    Please, put a checkmark ( ) or the word [RESOLVED] in your topic title if it was resolved, and rate the person who resolved it.

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: Callback Type Problem

    To save you a serious headache, you cannot use a non-static member function as the window procedure, because of the hidden "this" pointer that needs to be passed to each member function.

    Otherwise, if you're not using a member function, your code looks fine. Maybe try adding CALLBACK after LRESULT in your typdef -- CALLBACK is defined as __stdcall while the default calling convention is 'cdecl.' This might be the problem.

    edit: I think you put the calling convention inside the parentheses -- ie,

    typedef LRESULT( CALLBACK *grCallbackWndProc)(HWND, UINT, WPARAM, LPARAM);

    but I'm not sure
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Callback Type Problem

    sunburnt's answer is correct.

    But also, there's no need for the typedef. windows.h already contains one by the name of WNDPROC.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: Callback Type Problem

    Thanks a lot. Works like a charm.
    Please, put a checkmark ( ) or the word [RESOLVED] in your topic title if it was resolved, and rate the person who resolved it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width