• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

What to do with lParam in WindowProc() function?

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(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_getminmaxinfo.asp) 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."
0
krupini
Asked:
krupini
  • 3
  • 2
1 Solution
 
krupiniAuthor Commented:
And how to you get an address of a MAXINFO structure into a variable of type LPARAM, which is long, anyway?
0
 
jkrCommented:
You could just use a typecast:

LPMINMAXINFO lpmmi = (LPMINMAXINFO) lParam;

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

0
 
krupiniAuthor Commented:
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 ...
0
 
jkrCommented:
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.


LPMINMAXINFO lpmmi = (LPMINMAXINFO) lParam;
POINT ptMaxSize = lpmmi->ptMaxSize;
0
 
krupiniAuthor Commented:
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!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now