Sign in to follow this  
xyuri

request for member in something not a structure or union

Recommended Posts

xyuri    166
I am working with windows hook's, and previously (working on a different project) ran into this issue and couldnt figure out a resolution, but this time i really need to know. in the following callback function: LRESULT CALLBACK LowLevelKeyboardProc(int code, WPARAM wParam, LPARAM lParam) I have the following statement: DWORD laa = *lParam.vkCode; Microsoft's comment on the lParam parameter: lParam [in] Pointer to a KBDLLHOOKSTRUCT structure. and the structure is like this: typedef struct { DWORD vkCode; DWORD scanCode; DWORD flags; DWORD time; ULONG_PTR dwExtraInfo; } KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT; but, it get the error "request for member `vkCode' in something not a structure or union" I tried just declaring one of these structures on its own to test the idea, but still the same error. Why cant i access struct properties? I would appreciate any input on this. Thans :) (if not for replying, then for reading this much)

Share this post


Link to post
Share on other sites
pulpfist    528
Did you try (*lParam).vkCode? or lParam->vkCode?

Maybe an explicit cast is needed here

KBDLLHOOKSTRUCT *kbs = static_cast<KBDLLHOOKSTRUCT*>(lParam);
kbs->vkCode...

Share this post


Link to post
Share on other sites
xyuri    166
pulpfist, i'm using C ... and the following code doesnt work either:

KBDLLHOOKSTRUCT* laa = (KBDLLHOOKSTRUCT*)lParam;
DWORD dee = *laa.vkCode;


Am i correct in thinking that there is something very strange going on here? I've never had any troubles like this before :(

Share this post


Link to post
Share on other sites
pulpfist    528
Quote:

pulpfist, i'm using C ... and the following code doesnt work either:

KBDLLHOOKSTRUCT* laa = (KBDLLHOOKSTRUCT*)lParam;
DWORD dee = *laa.vkCode;

Am i correct in thinking that there is something very strange going on here? I've never had any troubles like this before :(


DWORD dee = laa->vkCode;
or
DWORD dee = (*laa).vkCode;

Share this post


Link to post
Share on other sites
jyk    2094
Did you try pulpfist's first two suggestions, (*lParam).vkCode and lParam->vkCode? In your latter example it would be DWORD dee = (*laa).vkCode.

Share this post


Link to post
Share on other sites
xyuri    166
Quote:
Original post by jyk
Did you try pulpfist's first two suggestions, (*lParam).vkCode and lParam->vkCode? In your latter example it would be DWORD dee = (*laa).vkCode.


To be honest, i didnt try the -> one because i thought it was c++ specific, but to be sure just then i tried it and it works 100% :D

I thought "laa->vkCode" was the alternative to "*laa.vkCode" though ?

Thanks for the help you guys, i really appreciate it :)

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
I thought "laa->vkCode" was the alternative to "*laa.vkCode" though ?
It is, but unless you clarify using parentheses, the compiler may have trouble resolving the latter. If laa is a pointer (as in your case), you want (*laa).vkCode; if laa is an object and vkCode is a pointer that you want to dereference, you want *(laa.vkCode); and if they're both pointers you'd need something like *((*laa).vkCode). Using -> syntax helps to avoid some of these ambiguities.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
basically by typeing

*lparam.vkcode is the same to the compiler as *(lparam.vkcode)

use the -> for simplicity sake

you was trying to get a value from a memory location stored at the long interpreted as a bad address, thats what that error means

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
-> is from like original c standard isnt it? i know even the oldest tutorials i use have it

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this