问题
I am trying to work with DirectInput keyboard, and my code is throwing a weird error. I can go through the creation, and setting of everything and they all return S_OK, but when I try to run
HRESULT hr;
hr = m_pDIKeyboard->GetDeviceState( sizeof(keyBuffer), (LPVOID)&keyBuffer );
hr comes back as (hex address) "access code is invalid", and when I do a check for
if(FAILED(hr))
it comes back as E_ACCESSDENIED there are no errors (or warnings for that matter) on the keyBuffer, or any part of the line.
any thoughts on this
回答1:
The documentation for IDirectInputDevice8::GetDeviceState give the following possible return values:
Return Value
If the method succeeds, the return value is DI_OK. If the method fails, the return value can be one of the following error values: DIERR_INPUTLOST, DIERR_INVALIDPARAM, DIERR_NOTACQUIRED, DIERR_NOTINITIALIZED, E_PENDING.
You should check that none of the DIERR_*
macros overlap with E_ACCESSDENIED
.
Further, some code I've seen handles E_ACCESSDENIED
the same way as DIERR_INPUTLOST
. You might want to try to re-Acquire
the input and have another go.
来源:https://stackoverflow.com/questions/9425575/directx-directinput-keyboard-throws-e-accessdenied