// Initialize DirectInput
bool CGame::InitializeDI(HINSTANCE hInst, HWND hWnd)
{
// Set up the Direct Input Stuff
HRESULT hr;
hr = (DirectInput8Create(hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_pDI, NULL));
if (FAILED(hr))
{
WriteToLog("ERROR initializing DirectInput8.");
return FALSE;
}
if (FAILED(m_pDI->CreateDevice(GUID_SysKeyboard, &m_pKeyboard, NULL)))
{
WriteToLog("ERROR Creating DirectInput Device.");
return FALSE;
}
if (FAILED(m_pKeyboard->SetDataFormat(&c_dfDIKeyboard)))
{
m_pKeyboard->Release();
WriteToLog("ERROR Setting DataFormat for DirectInput.");
return FALSE;
}
if (FAILED(m_pKeyboard->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))
{
m_pKeyboard->Release();
WriteToLog("ERROR Setting Cooperative Level for DirectInput.");
return FALSE;
}
if (FAILED(m_pKeyboard->Acquire()))
{
m_pKeyboard->Release();
WriteToLog("ERROR Acquire for DirectInput.");
return FALSE;
}
return true;
}
Problem with keyboard Acquire()
Just like the subject says my Acquire() function always fails and I have no idea why it's doing that. What can cause this function to fail?
Here's my code. The Acquire is at the very bottom.
Anybody have any ideas?
Quiggy.
[edited by - Quiggy on January 30, 2003 7:56:23 PM]
Shots in the dark:
1) Is the window (HWND) actually created and displayed by the time you call Aquire?
2) Have you tried creating a buffersize before aquiring?
1) Is the window (HWND) actually created and displayed by the time you call Aquire?
2) Have you tried creating a buffersize before aquiring?
DIPROPDWORD propdword; memset(&propdword, 0, sizeof(propdword)); propdword.diph.dwSize = sizeof(propdword); propdword.diph.dwHeaderSize = sizeof(DIPROPHEADER); propdword.diph.dwObj = 0; propdword.diph.dwHow = DIPH_DEVICE; propdword.dwData = 16; m_pKeyboard->SetProperty(DIPROP_BUFFERSIZE, &propdword.diph);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement