Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   Accessing To A Struct With A Given Pointer (http://www.go4expert.com/forums/accessing-struct-pointer-t461/)

AhmedHan 11Oct2005 19:39

Accessing To A Struct With A Given Pointer
 
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 11Oct2005 22:41

Re: Accessing To A Struct With A Given Pointer
 
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 12Oct2005 18:09

Re: Accessing To A Struct With A Given Pointer
 
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 12Oct2005 19:08

Re: Accessing To A Struct With A Given Pointer
 
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


All times are GMT +5.5. The time now is 03:54.