Skip to content

Commit

Permalink
Added check for xinput1_3, exiting the application if not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
matracey committed Apr 17, 2017
1 parent a103f70 commit 099a3d3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
45 changes: 41 additions & 4 deletions XInputBatteryMeter/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using XInputBatteryMeter.Properties;

namespace XInputBatteryMeter
{
Expand All @@ -9,12 +11,47 @@ public static void Main()
{
Console.WriteLine(@"Initializing.");

var poller = new BatteryStatusPoller();
var xinput13 = IsLibraryInstalled("xinput1_3.dll");
//var xinput910 = IsLibraryInstalled("xinput9_1_0.dll");

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new BatteryMeterApplicationContext(poller));
if (!xinput13)
{
MessageBox.Show(Resources.XInputNotFoundText, Resources.XInputNotFoundCaption, MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
var poller = new BatteryStatusPoller();

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new BatteryMeterApplicationContext(poller));
}

}

/// <summary>
/// Loads the specified module into the address space of the calling process. The specified module may cause other modules to be loaded.
/// </summary>
/// <param name="lpFileName">
/// <para>The name of the module. This can be either a library module (a .dll file) or an executable module (an .exe file).</para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is a handle to the module.</para>
/// <para>If the function fails, the return value is NULL.</para>
/// </returns>
[DllImport("kernel32", SetLastError = true)]
private static extern IntPtr LoadLibrary(string lpFileName);

/// <summary>
/// Checks if the specified Library is installed.
/// </summary>
/// <param name="fileName">The file to search for. This can be either a library module (a .dll file) or an executable module (an .exe file).</param>
/// <returns>true if the library is found; otherwise false.</returns>
private static bool IsLibraryInstalled(string fileName)
{
return LoadLibrary(fileName) != IntPtr.Zero;
}

}
}
18 changes: 18 additions & 0 deletions XInputBatteryMeter/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions XInputBatteryMeter/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
<data name="VersionString" xml:space="preserve">
<value>Version </value>
</data>
<data name="XInputNotFoundCaption" xml:space="preserve">
<value>XInput Not Found</value>
</data>
<data name="XInputNotFoundText" xml:space="preserve">
<value>XInput was not detected on this system. Please ensure you have the latest version of DirectX installed and try again. The application will now close.</value>
</data>
</root>

0 comments on commit 099a3d3

Please sign in to comment.