Fix for enumerating passed devices that are exclusively owned by another process #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.