CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2010
    Posts
    34

    What is actually LPARAM, WPARAM & LRESULT in detail?

    typedef UINT_PTR WPARAM;
    typedef LONG_PTR LPARAM;
    typedef LONG_PTR LRESULT;



    What actually there are?

    LPARAM & LRESULT. Can i cast of point them to a class object?


    For example,
    in a WndProc, and inside a switch case (maybe WM_CREATE), can I cast LRESULT to point to a RECT myrect and use it as return tp the WndProc


    LRESULT CALLBACK WndProc (...)
    {

    .....
    swith(Msg){
    case WM_CREATE:
    .....
    return lresult;
    break;
    ....
    }
    return :efWindowProc(hwnd, iMsg, wParam, lParam);
    }





    then in somehere else WndProc (a child window), i can do this to retrieve the pointer to the myrect such as

    Rect rect = SendMessage(hwndparent, WM_CREATE, null, null);



    It is possible? How do i cast it?

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: What is actually LPARAM, WPARAM & LRESULT in detail?

    What actually there are?
    Just numbers of certain size.
    LPARAM & LRESULT. Can i cast of point them to a class object?
    It is possible?
    Yes. But you should take special care about referenced object: its life cycle must allow you to access it in message handler. Until it gets handled you must not do anything that results in object deletion/relocation.
    How do i cast it?
    Any C++ compliant way you do. Typically it happens by taking object address and casting it to corresponding xPARAM.
    Last edited by Igor Vartanov; July 19th, 2010 at 10:24 AM.
    Best regards,
    Igor

  3. #3
    Join Date
    Jun 2010
    Posts
    34

    Re: What is actually LPARAM, WPARAM & LRESULT in detail?

    life cycle, you are right about it. I been put in my note from the beginning. Kind of dangerous if I miss it.


    Can you show some example mate. Can I return a lresult (which point to a, say, a RECT) for the wndproc().

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: What is actually LPARAM, WPARAM & LRESULT in detail?

    Code:
    // you can do this
    RECT g_myRect = {0}; // of global scope
    
    LRESULT CALLBACK WndProc (...)
    {
    
        .....
        swith(Msg){
        case WM_CREATE:
            .....
            lresult = reinterpret_cast<LRESULT>(&g_myRect);
            return lresult;
        ....
        }
        return ::DefWindowProc(hwnd, iMsg, wParam, lParam);
    }
    Code:
    // you cannot do that
    LRESULT CALLBACK WndProc (...)
    {
    
        .....
        swith(Msg){
        case WM_CREATE:
            .....
            RECT myRect = {0}; // of function scope, to be destroyed on function return!!!
            .....
            lresult = reinterpret_cast<LRESULT>(&myRect);
            return lresult;
        ....
        }
        return ::DefWindowProc(hwnd, iMsg, wParam, lParam);
    }
    Best regards,
    Igor

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: What is actually LPARAM, WPARAM & LRESULT in detail?

    BTW, WM_CREATE is very rigid in aspect of returning LRESULT values.
    Best regards,
    Igor

  6. #6
    Join Date
    Jun 2010
    Posts
    34

    Re: What is actually LPARAM, WPARAM & LRESULT in detail?

    Hahahah. Just for example. Anyways, that clear me up and now I know why MS have wparam and lparam as one for numeric data and one can be cast to point to any object.

    Learn one more thing today. Thanks Mate. Really, thanks. I been sitting here from 5.30pm after work today and now its 12am in Malaysia. But it really a rewarding day, today. coding come to several milestone, and then, you. Thanks
    Last edited by Irwan; July 19th, 2010 at 11:01 AM.

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

Featured