Skip to content

Commit

Permalink
Detect window handle error for running in cmd.exe. Added product guid…
Browse files Browse the repository at this point in the history
…s for Teensy and Cyborg EVO
  • Loading branch information
Bob Helander committed Dec 10, 2020
1 parent cb960b1 commit 374ba92
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
4 changes: 3 additions & 1 deletion EDForceFeedback/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"NOTES2": "The device search will match on either value",
"Xbox One For Windows": "ProductGuid = 02dd045e-0000-0000-0000-504944564944 ProductName = 'Controller (Xbox One For Windows)'",
"MSFF2": "ProductGuid = 001b045e-0000-0000-0000-504944564944 ProductName = 'SideWinder Force Feedback 2 Joystick'",
"Cyborg 3D Force Stick": "ProductGuid = ff1206a3-0000-0000-0000-504944564944"
"Saitek Cyborg 3D Force Stick": "ProductGuid = ff1206a3-0000-0000-0000-504944564944",
"Saitek Cyborg Evo Force Stick": "ProductGuid = ffb506a3-0000-0000-0000-504944564944",
"Teensy Boards": "ProductGuid = 230028de-0000-0000-0000-504944564944 ProductName = IMU"
},

"Devices": [
Expand Down
4 changes: 3 additions & 1 deletion EDForceFeedback/settingsMSFFB2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"NOTES2": "The device search will match on either value",
"Xbox One For Windows": "ProductGuid = 02dd045e-0000-0000-0000-504944564944 ProductName = 'Controller (Xbox One For Windows)'",
"MSFF2": "ProductGuid = 001b045e-0000-0000-0000-504944564944 ProductName = 'SideWinder Force Feedback 2 Joystick'",
"Cyborg 3D Force Stick": "ProductGuid = ff1206a3-0000-0000-0000-504944564944"
"Saitek Cyborg 3D Force Stick": "ProductGuid = ff1206a3-0000-0000-0000-504944564944",
"Saitek Cyborg Evo Force Stick": "ProductGuid = ffb506a3-0000-0000-0000-504944564944",
"Teensy Boards": "ProductGuid = 230028de-0000-0000-0000-504944564944 ProductName = IMU"
},

"Devices": [
Expand Down
4 changes: 3 additions & 1 deletion EDForceFeedback/settingsXbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"NOTES2": "The device search will match on either value",
"Xbox One For Windows": "ProductGuid = 02dd045e-0000-0000-0000-504944564944 ProductName = 'Controller (Xbox One For Windows)'",
"MSFF2": "ProductGuid = 001b045e-0000-0000-0000-504944564944 ProductName = 'SideWinder Force Feedback 2 Joystick'",
"Cyborg 3D Force Stick": "ProductGuid = ff1206a3-0000-0000-0000-504944564944"
"Saitek Cyborg 3D Force Stick": "ProductGuid = ff1206a3-0000-0000-0000-504944564944",
"Saitek Cyborg Evo Force Stick": "ProductGuid = ffb506a3-0000-0000-0000-504944564944",
"Teensy Boards": "ProductGuid = 230028de-0000-0000-0000-504944564944 ProductName = IMU"
},

"Devices": [
Expand Down
4 changes: 3 additions & 1 deletion EDForceFeedback/settingsXboxAndCyborg.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"NOTES2": "The device search will match on either value",
"Xbox One For Windows": "ProductGuid = 02dd045e-0000-0000-0000-504944564944 ProductName = 'Controller (Xbox One For Windows)'",
"MSFF2": "ProductGuid = 001b045e-0000-0000-0000-504944564944 ProductName = 'SideWinder Force Feedback 2 Joystick'",
"Cyborg 3D Force Stick": "ProductGuid = ff1206a3-0000-0000-0000-504944564944"
"Saitek Cyborg 3D Force Stick": "ProductGuid = ff1206a3-0000-0000-0000-504944564944",
"Saitek Cyborg Evo Force Stick": "ProductGuid = ffb506a3-0000-0000-0000-504944564944",
"Teensy Boards": "ProductGuid = 230028de-0000-0000-0000-504944564944 ProductName = IMU"
},

"Devices": [
Expand Down
4 changes: 3 additions & 1 deletion EDForceFeedback/settingsXboxAndMSFFB2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"NOTES2": "The device search will match on either value",
"Xbox One For Windows": "ProductGuid = 02dd045e-0000-0000-0000-504944564944 ProductName = 'Controller (Xbox One For Windows)'",
"MSFF2": "ProductGuid = 001b045e-0000-0000-0000-504944564944 ProductName = 'SideWinder Force Feedback 2 Joystick'",
"Cyborg 3D Force Stick": "ProductGuid = ff1206a3-0000-0000-0000-504944564944"
"Saitek Cyborg 3D Force Stick": "ProductGuid = ff1206a3-0000-0000-0000-504944564944",
"Saitek Cyborg Evo Force Stick": "ProductGuid = ffb506a3-0000-0000-0000-504944564944",
"Teensy Boards": "ProductGuid = 230028de-0000-0000-0000-504944564944 ProductName = IMU"
},

"Devices": [
Expand Down
20 changes: 19 additions & 1 deletion ForceFeedbackSharpDx/MicrosoftSidewinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace ForceFeedbackSharpDx
{
public class MicrosoftSidewinder
{
private const uint WINDOW_HANDLE_ERROR = 0x80070006;

// Microsoft Force Feedback 2
//private static Guid product = new Guid("001b045e-0000-0000-0000-504944564944");

Expand Down Expand Up @@ -83,7 +85,23 @@ public bool ForceFeedback2(string productGuid, string productName, bool AutoCent
// DirectX requires a window handle to set the CooperativeLevel
var handle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;

joystick.SetCooperativeLevel(handle, CooperativeLevel.Exclusive | CooperativeLevel.Background);
try
{
joystick.SetCooperativeLevel(handle, CooperativeLevel.Exclusive | CooperativeLevel.Background);
}
catch(SharpDX.SharpDXException ex ) when ((uint)ex.HResult == WINDOW_HANDLE_ERROR)
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine($"***********************************************************************************");
Console.WriteLine();
Console.WriteLine($" Unable to access window handle. Do not run EDForceFeedback.exe in a console window.");
Console.WriteLine();
Console.WriteLine($"***********************************************************************************");
Console.WriteLine();
Console.WriteLine();
return false;
}

// Autocenter on
joystick.Properties.AutoCenter = AutoCenter;
Expand Down

0 comments on commit 374ba92

Please sign in to comment.