Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for enumerating passed devices that are exclusively owned by another process #12

Merged
merged 1 commit into from
Sep 28, 2016

Conversation

briankendall
Copy link

I discovered a rather show stopping bug with vJoy just earlier today. I use it in conjunction with DS4Windows, a piece of software that translates input from a DualShock 4 controller to Xinput. One of the features DS4Windows has is the ability to exclusively take control of the DualShock 4 device so that other applications can't access it (which prevents cases of double input). When I used this feature in conjunction with vJoy, all of a sudden vJoy API functions would start to fail.

I discovered that if the DS4 device was enumerated before any of the vJoy devices, any attempt to access properties of those vJoy devices would fail. Worse yet, if the DS4 device was enumerated before all of the vJoy devices, then the entire vJoy API would fall over.

The issue seems to be in vJoyInterface.cpp: when GetHandleByIndex calls CreateFile, if that function fails GetHandleByIndex returns NULL, ceasing any further enumeration of devices in GetDeviceIndexById. However, CreateFile will fail if the device it is attempting to open is exclusively owned by another process. So I changed it to return INVALID_HANDLE_VALUE so that it would continue enumeration. That seems to have fixed things. Hopefully this is the correct fix for this issue.

@shauleiz
Copy link
Owner

Seems to solve a common problem that I had no idea how to tackle.
I will go over your code within the next 24 hours and get back to you.

@evilC
Copy link

evilC commented Sep 27, 2016

Many thanks for the code Brian!
@shaul - This may well be the cause of the Saitek issue.
By the way, Brian, we have been discussing disabling controllers for a while now, as obviously it would be nice to have some kind of API or something that allowed us to hide physical sticks etc so we can do true remapping via vJoy. Please do feel free to chip in on our thread as it sounds like you may know a thing or two about the subject.

@briankendall
Copy link
Author

Glad I could help! I don't actually have very much experience working with Windows' low level device API, but it was an unusually good stroke of luck that I happened to be researching how DS4Windows and InputMapper hide devices (with this thread that Clive started coincidentally being one of the things that helped me the most) and that so happened to be directly related to why vJoy wasn't working. That and I could switch my system in and out of a working state and close in on the problem area with print statements. There's no substitute for being able to reliably reproduce the problem.

Now that I think about it, I bet you guys will want to change the other places in GetHandleByIndex() where it returns NULL, since any device that triggers those error conditions will end up preventing vJoy from working if they come earlier in the enumeration order. It also seems to go against this comment.

@shauleiz shauleiz merged commit 76f18ab into shauleiz:master Sep 28, 2016
@shauleiz
Copy link
Owner

This is an important fix Brian.
I would like to investigate the other NULLs to see if they should also be changed.
Thank you!

@shauleiz
Copy link
Owner

Released as tag v2.17.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants