Skip to main content
gamedev.net
🔒 Locked

Passing char array to function for dinput8

Started by pteri498 2 replies 700+ views
Original Post
pteri498
pteri498
Hi. I'm trying to work out a class for Direct Input 8, and this requires me to pass the key buffer into the function to use GetDeviceState. Here's the code:

void di8::getKeyboardState(char buffer[])
{
	pdiDevice->GetDeviceState( sizeof(&buffer),(void*)&buffer);
};

//function call in WinMain:
char keys[256];
//... input is the name of my di8 class
input->getKeyboardState(keys);

Now if you're familiar with how GetDeviceState works, you'll see right off that this is how the function would take input if the character array was in the exact same function as GetDeviceState's call. But this time I'm passing it into the function. Now I'm checking the data on "keys", and none fo the values are changing. I'm breakpointing inside this function, and in fact "buffer"'s members amount to 1 entry: the number 0. I'm not sure exactly what's wrong here. All I do know is that this function is not changing the "keys" array. What can I do to fix this? note: I posted this in General Programming a little while ago, but I'm finding this to be a little more API specific.
Madhed
Madhed
Hi there.

try this

pdiDevice->GetDeviceState( 256,(void*)buffer);

instead of this

pdiDevice->GetDeviceState( sizeof(buffer),(void*)&buffer);

with &buffer you get the address of the pointer, not the value of the pointer
to the array.

you could also change the function declaration to:

void di8::getKeyboardState(char* buffer)

and do pdiDevice->GetDeviceState( 256,(void*)buffer);

EDIT: corrected a big typo...

[Edited by - Madhed on January 24, 2006 8:33:54 PM]
darkelf2k5
darkelf2k5
Quote:
note: I posted this in General Programming a little while ago, but I'm finding this to be a little more API specific.


Nope, this problem has no relation to Directx at all. Anyway, why don't you just pass it as a pointer or use some other global var. This is a language feature, but rarely used.

Every time you implement a singleton, God kills a kitten. Please, think of the kittens!
CHTHONIC
CHTHONIC
Hey pteri,

For starters with DirectInput8 devices you should Poll() for the device before you try and get its state (see DX SDK for complete info). This should be done in a continuous loop until you either have the device or an error is thrown (i.e. DIERR_INPUTLOST or DIERR_NOTACQUIRED).

As regards to your GetDeviceState call, I'm not to sure why you are doing it the way you are but the following may help:

pdiDevice->GetDeviceState(256,(LPVOID)&keys)

To populate your "char keys[256]" array with the current state of all the keys.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.