DirectInputDevice8::Acquire returns E_ACCESSDENIED

Started by
6 comments, last by peter86 21 years, 5 months ago
When I set the cooperative level like below Acquire() returns E_ACCESSDENIED, but if I skip the cooperative level, it works fine. What´s wrong?
  
if( FAILED( hr = g_pKeyboard->SetCooperativeLevel( hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE ) ) )
{
	return hr;
}

if( FAILED( hr = g_pKeyboard->Acquire() ) )
{
	return hr;
}
  
____________________________________________________________ Nothing dosen´t exist. Does it?
Advertisement
It works fine with DISCL_BACKGROUND, so why not DISCL_FOREGROUND?

[edited by - peter86 on December 3, 2002 2:17:20 PM]
maybe your application is in the background when you try to acquire the device so it'll fail, because it cant acquire the device util your app is in focus. I dunno for sure, could you maybe post some code, initialization caode that is.

On another note why dont you just get rid of the if(FAILED( checking on the Acquire method. That way when you use the function GetDeviceState(...) and that fails, then you can enter a loop until the device is acquired or something

::: Al:::
[Triple Buffer V2.0] - Resource leak imminent. Memory status: Fragile

[edited by - alfmga on December 3, 2002 2:33:56 PM]
[size=2]aliak.net
It''s very annoying, as I''m experiencing the same thing now!

Input code which USED to work just fine, now suddenly doesn''t.

I''ve rebooted the machine, I''ve tried to use SetFocus to force the window to the foreground.

Nada.
Learn about game programming!Games Programming in C++: Start to Finish
quote:Original post by wazoo69
It''s very annoying, as I''m experiencing the same thing now!

Input code which USED to work just fine, now suddenly doesn''t.

I''ve rebooted the machine, I''ve tried to use SetFocus to force the window to the foreground.

Nada.


Just acquire when GetDeviceState returns DIERR_INPUTLOST or DIERR_NOTACQUIRED and you´ll get rid of the annoying problem .
This could happen if your creating direct input before the window is set to visible. (ie before the ShowWindow() call) I''m not sure if the application is in the foreground until it is visible but others here might be able to clarify this if it isn''t the case.

Do you have anything running in the taskbar that would cause your application to move to the background? Are you running a profiler that could cause this? Virus scanner? IM application?

In anycase, as long as all that is an error is that your not getting the keyboard acquired, you can handle that during GetDeviceState or GetDeviceData as mentioned above. You should handle it here regardless as that is good practice.

I went ahead and changed the (FAILED()) checks in my code. Every DirectInput call now passes the result to ''hr'' and I test all of the known return values according to MSDN function specs and record specifics to log files. It helps to have this information when DirectInput begins to fail.

Kressilac
ps Side note. Use GetDeviceData instead of GetDeviceState if absolutely every keypress must be captured. GetDeviceState stands a good chance of missing keys.
Derek Licciardi (Kressilac)Elysian Productions Inc.
Hmm I wonder if that''s it?

In my old codebase, one of the window creation parameters was set to WS_VISIBLE (and the input worked)

Yet now, I removed that, and am just calling ShowWindow after the device initialization..

Learn about game programming!Games Programming in C++: Start to Finish
My code uses DISCL_FOREGROUND with DISCL_NONEXCLUSIVE, but before calling Acquire() it calls SetDataFormat(&c_dfDIKeyboard). You need to do that. c_dfDIKeyboard is defined by DirectX so just type that verbatim ("g_pKeyboard->SetDataFormat( &c_dfDIKeyboard )") and it should work. The call goes inbetween SetCooperativeLevel and Acquire.

~CGameProgrammer( );

[edited by - CGameProgrammer on December 5, 2002 1:53:10 AM]
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.

This topic is closed to new replies.

Advertisement