Okay, aparently I am a bit lost.
I cannot put my Enumdevices Callback inside a Class right? (If I can please explain how, it has not worked for me yet) but I want the organization of having all my directX pointers inside a class. I have done this with Direct 3D, but now I need input..... and I am trying to avoid using a global. I know that would work, so if there is no other option I will do it...
Alright, here is my code, this is just me organizing stuff from a book, there is much room for improvement, but I will work on that once I get everything from DirectX into nice little classes.
I am strange like that.
Here is the code in question (only snippits):
class eInput
{
public:
IDirectInput8 *iDI; // DirectInput component
IDirectInputDevice8 *iDIDJoysticks; // Enum Joystick device
IDirectInputDevice8 *iDIJoy; // Joystick device
IDirectInputDevice8 *iDIMouse;
IDirectInputDevice8 *iDIKeyboard;
HWND hwnd;
eInput();
~eInput();
bool InitKeyboard();
bool InitMouse();
bool InitJoystick();
bool KRead( void *DataBuffer, long BufferSize);
bool MRead( void *DataBuffer, long BufferSize);
bool JRead( void *DataBuffer, long BufferSize);
bool CALLBACK EnumJoysticks(LPCDIDEVICEINSTANCE pdInst, LPVOID pvRef);
bool Init();
};
the code that calls this and it expantion:
bool eInput::InitJoystick()
{
iDI->EnumDevices(DI8DEVTYPE_JOYSTICK, EnumJoysticks, NULL, DIEDFL_ATTACHEDONLY);
// Everything was a success
return true;
}
bool CALLBACK eInput::EnumJoysticks(LPCDIDEVICEINSTANCE pdInst, LPVOID pvRef)
{
DIPROPRANGE dipr;
DIPROPDWORD dipdw;
iDIDJoysticks = NULL;
// Create the device object using global DirectInput object
if(FAILED(iDI->CreateDevice(pdInst->guidInstance, &iDIDJoysticks, NULL)))
return DIENUM_CONTINUE;
// Set the data format
if(FAILED(iDIDJoysticks->SetDataFormat(&c_dfDIJoystick))) {
iDIDJoysticks->Release();
iDIDJoysticks = NULL;
return DIENUM_CONTINUE;
}
// Set the cooperative mode
if(FAILED(iDIDJoysticks->SetCooperativeLevel(hwnd,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE))) {
iDIDJoysticks->Release();
iDIDJoysticks = NULL;
return DIENUM_CONTINUE;
}
// Clear out the structure first
ZeroMemory(&dipr, sizeof(DIPROPRANGE));
dipr.diph.dwSize = sizeof(dipr);
dipr.diph.dwHeaderSize = sizeof(dipr);
dipr.diph.dwObj = DIJOFS_X;
dipr.diph.dwHow = DIPH_BYOFFSET; // offset into data format
dipr.lMin = -1024;
dipr.lMax = 1024;
if(FAILED(iDIDJoysticks->SetProperty(DIPROP_RANGE, &dipr.diph))) {
iDIDJoysticks->Release();
iDIDJoysticks = NULL;
return DIENUM_CONTINUE;
}
dipr.diph.dwObj = DIJOFS_Y;
if(FAILED(iDIDJoysticks->SetProperty(DIPROP_RANGE, &dipr.diph))) {
iDIDJoysticks->Release();
iDIDJoysticks = NULL;
return DIENUM_CONTINUE;
}
// Set X deadzone to 15%
dipdw.diph.dwObj = DIJOFS_X;
dipdw.dwData = 1500;
if(FAILED(iDIJoy->SetProperty(DIPROP_DEADZONE, &dipdw.diph))) {
iDIDJoysticks->Release();
iDIDJoysticks = NULL;
return DIENUM_CONTINUE;
}
// Set Y deadzone
dipdw.diph.dwObj = DIJOFS_Y;
if(FAILED(iDIJoy->SetProperty(DIPROP_DEADZONE, &dipdw.diph))) {
iDIDJoysticks->Release();
iDIDJoysticks = NULL;
return DIENUM_CONTINUE;
}
// Acquire the device for use
if(FAILED(iDIDJoysticks->Acquire())) {
iDIDJoysticks->Release();
iDIDJoysticks = NULL;
return DIENUM_CONTINUE;
}
// Stop enumeration
return DIENUM_STOP;
}
Thanks. I have been working with this particular code for a grand total of about 3 weeks now! DirectX may be the cause of head aches, but I think it will be worth the agrrivation!
___________________________________________________Optimists see the glass as Half FullPessimists See the glass as Half EmptyEngineers See the glass as Twice as big as it needs to be