954,180 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Accessing To A Struct With A Given Pointer

We have a struct defined as :
typedef struct tagWINDOWPOS { /* wp */[INDENT] HWND hwnd;
HWND hwndInsertAfter;
int x;
int y;
int cx;
int cy;
UINT flags;[/INDENT]} WINDOWPOS;

Then we are sent a message...WM_WINDOWPOSCHANGING
[INDENT] WPARAM wParam
LPARAM lParam;[/INDENT]
Parameters

wParam[INDENT]This parameter is not used.[/INDENT]lParam[INDENT]Pointer to a WINDOWPOS structure that contains information about the window's new size and position.[/INDENT]

And this is the code which gets the messagecase WM_WINDOWPOSCHANGING:[INDENT] WINDOWPOS * pWinPos;
pWinPos = lParam;
break;[/INDENT]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

AhmedHan
Junior Poster in Training
71 posts since Apr 2005
Reputation Points: 13
Solved Threads: 1
 

pWinPos is not constant. but you do need a cast. either an old c style or a reinterpret_cast(lParam)

Stoned_coder
Junior Poster
164 posts since Jul 2005
Reputation Points: 19
Solved Threads: 5
 

IsWINDOWPOS wp;
WINDOWPOS * pwp;
pwp = ℘convenient?

Then we can access to the sub-fields this way :pwp->x
pwp->uflags
etc...

AhmedHan
Junior Poster in Training
71 posts since Apr 2005
Reputation Points: 13
Solved Threads: 1
 

i prefer....

WINDOWPOS* wp = (WINDOWPOS*)lParam;

Stoned_coder
Junior Poster
164 posts since Jul 2005
Reputation Points: 19
Solved Threads: 5
 

Thanks.
Type conversion works well.

AhmedHan
Junior Poster in Training
71 posts since Apr 2005
Reputation Points: 13
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You