request for member in something not a structure or union

Started by
8 comments, last by pulpfist 18 years, 4 months ago
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)
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend
Advertisement
Did you try (*lParam).vkCode? or lParam->vkCode?

Maybe an explicit cast is needed here

KBDLLHOOKSTRUCT *kbs = static_cast<KBDLLHOOKSTRUCT*>(lParam);
kbs->vkCode...
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 :(
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend
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;
Did you try pulpfist's first two suggestions, (*lParam).vkCode and lParam->vkCode? In your latter example it would be DWORD dee = (*laa).vkCode.
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 :)
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend
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.
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
-> is from like original c standard isnt it? i know even the oldest tutorials i use have it
I think its as old as Thompson himself

This topic is closed to new replies.

Advertisement