Accessing To A Struct With A Given Pointer

AhmedHan's Avatar, Join Date: Oct 2005
Go4Expert Member
We have a struct defined as :


Quote:
typedef struct tagWINDOWPOS { /* wp */
HWND hwnd;

HWND hwndInsertAfter;
int x;
int y;
int cx;
int cy;
UINT flags;
} WINDOWPOS;
Then we are sent a message...
Quote:
WM_WINDOWPOSCHANGING

WPARAM wParam

LPARAM lParam;
Parameters




wParam
This parameter is not used.
lParam
Pointer to a WINDOWPOS structure that contains information about the window's new size and position.
And this is the code which gets the message



Quote:
case WM_WINDOWPOSCHANGING:
WINDOWPOS * pWinPos;

pWinPos = lParam;
break;
lParam contains the address of the struct. Here we want to access to the struct.

But there is a problem with the code. pWinPos is a constant pointer, so we can't simply assign an address to it.

So, finally, here is my question...
How can I access to the WINDOWPOS struct whose address is given by lParam

PS : I am using Dev-C++
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Welcome to the Programming forum.
Quote:
Originally Posted by AhmedHan
How can I access to the WINDOWPOS struct whose address is given by lParam
By type casting the lParam pointer to the WINDOWPOS pointer.

pWinPos = (WINDOWPOS *)lParam;

Thanks
Shabbir Bhimani
AhmedHan's Avatar, Join Date: Oct 2005
Go4Expert Member
That one works, thank you.

Actually, I tried the same thing, but I put the * oparetor to the wrong place :
pWinPos = (* WINDOWPOS)lParam; instead of pWinPos = (WINDOWPOS *)lParam;
That is silly of me
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by AhmedHan
That one works, thank you.

Actually, I tried the same thing, but I put the * oparetor to the wrong place :
pWinPos = (* WINDOWPOS)lParam; instead of pWinPos = (WINDOWPOS *)lParam;
That is silly of me
The silly's can come at any time and if you share the knowledge and queries with other you tend to reduce them. haha