0

I am trying to build an application that have exclusive access over a gamepad. Which mean when my application run, no other application will receive or react to the gamepad action like button press, wheel move,...

My approach to the present is using DirectInput, set flag: DISCL_EXCLUSIVE | DISCL_BACKGROUND.

However, I realize that it seems the DISCL_EXCLUSIVE has no effect? Whenever i set DISCL_EXCLUSIVE or DISCL_NONEXCLUSIVE it is the same.

And yesterday I found this: http://www.gamedev.net/topic/656250-directinput-exclusive-access-to-joypad/ According what he mention, this flag does nothing?

So is there any other solution for my problem? Thanks.

  • 1
    Why would you want to do that? That's a very unfriendly behaviour from an application. – Luaan Jul 11 '14 at 08:59

1 Answers1

0

But DISCL_EXCLUSIVE | DISCL_BACKGROUND is not going to give you exclusive access to the device. A foreground application will always have precedence, exclusive or not. You shouldn't steal control from the user.

So what is it good for? Multiple applications running in the background. That's pretty much the only use case, and also the only point that's reasonable from the user perspective. When an application requests exclusive access to a device that's already being used exclusively, one of them will fail (IIRC the older one) and will have to reacquire the device (which it of course shouldn't, because that will simply end in a war for control :)).

For most cases, you should simply use DISCL_NONEXCLUSIVE | DISCL_FOREGROUND. Exclusive background access is only intended for things like controlling your media player or something like that :)

Luaan
  • 62,244
  • 7
  • 97
  • 116
  • That's is my assigned task. I need to build a mechanism/application that meet the desire: Non other app will be able to access the gamepad once my app has acquire it. It's pretty much like owning, occupying resources. And the reason I do not know myself :)) Just need do it :( – user3819161 Jul 11 '14 at 09:43
  • @user3819161 Well, you're done then - it's impossible, plain and simple :) It was only possible back when security wasn't considered a big issue on desktops, i.e. before desktop Windows switched over to the NT core. Short of writing your own device drivers, there's no way to enforce this. The security always leaks in a few places of course, but exploiting those will just get you tons of compatibility issues. – Luaan Jul 11 '14 at 09:48
  • Thanks for your help. I will just report to my boss :D There is only one thing still in my mind: Why Microsoft provide those options however the behaviors is not as it seems to be? At least they could warn us? – user3819161 Jul 14 '14 at 01:02
  • @user3819161 Well, it's described nicely in MSDN, which is basically the documentation for all things MS :) They even show the reasons for using `EXCLUSIVE` and how to do that. And of course, it used to work the way you expect it to - back in the Windows 95 family. – Luaan Jul 14 '14 at 08:23