What to do with lParam in WindowProc() function?

Posted on 2005-04-17
Last Modified: 2013-12-03
Been C#ing for a while now, almost forgot C/C++.

Now then, I am making a Win32 API app in C+. My main form listens for WM_GETMINMAXINFO message. From MSDN documentation( lParam contains an address to MINMAXINFO structure. Now here is the question, what can I do with that address?

How can I tell my compiler: "I have an address stored in that lParam that points to a MAXINFO structure. I need to either access the members of the pointed MAXINFO structure directly, or create a new MAXINFO strucure that would be a copy of the MAXINFO structure pointed by lParam."
Question by:krupini

    Author Comment

    And how to you get an address of a MAXINFO structure into a variable of type LPARAM, which is long, anyway?
    LVL 86

    Expert Comment

    You could just use a typecast:


    BTW, that's almost the same example as the one from the docs on WM_GETMINMAXINFO.


    Author Comment

    But so it's more clear to me, how is it that lParam, being of type long and NOT pointer to long (or _w64 long, whatever that is) constains an address of a MAXINFO structure?

    Here is an example:

    int number = 5;
    long address = &number; // Does not work
    long* address = &number; // That works, but 'address' is of type pointer to long, not just long

    The thing is, reading MSDN documentation on Win32 API, it quite so often happens that wParam and lParam point to structures of different kinds. How is it that a value of type long can contain an address of anything? It is not a pointer, just long. How do u make that happen? If I know how to make that happen, then everything will make more sence to me ...
    LVL 86

    Accepted Solution

    Your sample should be more like

    int number = 5;
    long* address = &number;
    long anothernumber = *address;

    then you'll receive the desired results, The "LPARAM" type can represent anything you could pack int 32bits, let it be a pointer to a struct or anything else. Once you've casted it to the correct type, you can do it for anything you want, e.g.

    POINT ptMaxSize = lpmmi->ptMaxSize;

    Author Comment

    Ahh, I get it now. I always thought that when you store an address of a variable, you must declare a pointer of the same type, e.g.

    long num  = 5;
    int num2 = 5;

    long* address = &num // stores address of num;
    long* address = &num2 // can't do, u need a pointer of type int*, not long*, will not compile
    int* address = &num2 // above problem fixed

    But, now I know, you can do this:

    long address = (long)&num2; // stores address of num2, yet not a pointer, cool!
    long* address = (long*)&num2 // prob. shouldn't do this, but still cool, I just casted a pointer!

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
    A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now