Accessing To A Struct With A Given Pointer

Reply

Join Date: Apr 2005
Posts: 71
Reputation: AhmedHan is an unknown quantity at this point 
Solved Threads: 1
AhmedHan's Avatar
AhmedHan AhmedHan is offline Offline
Junior Poster in Training

Accessing To A Struct With A Given Pointer

 
0
  #1
Oct 11th, 2005
We have a struct defined as :
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...
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
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

Re: Accessing To A Struct With A Given Pointer

 
0
  #2
Oct 11th, 2005
pWinPos is not constant. but you do need a cast. either an old c style or a reinterpret_cast<WINDOWPOS*>(lParam)
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 71
Reputation: AhmedHan is an unknown quantity at this point 
Solved Threads: 1
AhmedHan's Avatar
AhmedHan AhmedHan is offline Offline
Junior Poster in Training

Re: Accessing To A Struct With A Given Pointer

 
0
  #3
Oct 11th, 2005
Is
WINDOWPOS wp;
WINDOWPOS * pwp;
pwp = &wp;
convenient?

Then we can access to the sub-fields this way :
pwp->x
pwp->uflags
etc...
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

Re: Accessing To A Struct With A Given Pointer

 
0
  #4
Oct 11th, 2005
i prefer....

WINDOWPOS* wp = (WINDOWPOS*)lParam;
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 71
Reputation: AhmedHan is an unknown quantity at this point 
Solved Threads: 1
AhmedHan's Avatar
AhmedHan AhmedHan is offline Offline
Junior Poster in Training

Re: Accessing To A Struct With A Given Pointer

 
0
  #5
Oct 12th, 2005
Thanks.
Type conversion works well.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC