GetDeviceState problem

Started by
1 comment, last by crystallight111 19 years, 7 months ago
Hi, I have a struct like this: struct KeyboardState { uchar keys[256]; } then I want to update the keyboard state like this: KeyboardState* keyboard = new KeyboardState(); hr = di_keyboard->GetDeviceState(sizeof(keyboard->keys), (LPVOID)keyboard->keys); (LPVOID)keyboard->keys is the thing that doesn't work, how do I do it correctly? There's a reason that I put the keys buffer in it's own struct, I tried it with a simple uchar keys[256] as in the documentation just to make sure and it works with that. So I hope you can help me :)
Advertisement
For one, you don't need the parentheses after KeyboardState in your call to operator new. Other than that, I'm not immediately seeing any problem. The (LPVOID) cast should, from my memory, apply to the ->keys variable, not the keyboard variable. First of all, make sure that your keyboard pointer is valid. Secondly, try putting parentheses around keyboard->keys, just to see what happens.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Yes, the keyboard ptr is valid, I still receive a segmentation fault with the parentheses around keyboard->keys however the program won't crash immediately now.

This topic is closed to new replies.

Advertisement