943,778 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2008
  • C RSS
Oct 11th, 2005
0

Accessing To A Struct With A Given Pointer

Expand Post »
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
Similar Threads
Reputation Points: 13
Solved Threads: 1
Junior Poster in Training
AhmedHan is offline Offline
71 posts
since Apr 2005
Oct 11th, 2005
0

Re: Accessing To A Struct With A Given Pointer

pWinPos is not constant. but you do need a cast. either an old c style or a reinterpret_cast<WINDOWPOS*>(lParam)
Reputation Points: 19
Solved Threads: 5
Junior Poster
Stoned_coder is offline Offline
164 posts
since Jul 2005
Oct 11th, 2005
0

Re: Accessing To A Struct With A Given Pointer

Is
Quote ...
WINDOWPOS wp;
WINDOWPOS * pwp;
pwp = &wp;
convenient?

Then we can access to the sub-fields this way :
Quote ...
pwp->x
pwp->uflags
etc...
Reputation Points: 13
Solved Threads: 1
Junior Poster in Training
AhmedHan is offline Offline
71 posts
since Apr 2005
Oct 11th, 2005
0

Re: Accessing To A Struct With A Given Pointer

i prefer....

WINDOWPOS* wp = (WINDOWPOS*)lParam;
Reputation Points: 19
Solved Threads: 5
Junior Poster
Stoned_coder is offline Offline
164 posts
since Jul 2005
Oct 12th, 2005
0

Re: Accessing To A Struct With A Given Pointer

Thanks.
Type conversion works well.
Reputation Points: 13
Solved Threads: 1
Junior Poster in Training
AhmedHan is offline Offline
71 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: a short question
Next Thread in C Forum Timeline: Fibonacci number





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC