Automatic switching between 32 and 64-bit hidapi dlls (#542)

- detect bitness of system and change dll appropriately automatically

Co-authored-by: Shuken <shukenmg@iuvenisstudios.ga>
This commit is contained in:
shukenmg 2020-09-22 20:35:54 +08:00 committed by GitHub
parent 06edcb1be5
commit 43786c12d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 1 deletions

View file

@ -236,7 +236,10 @@
<Content Include="Icons\snes.png" /> <Content Include="Icons\snes.png" />
<None Include="Properties\app.manifest" /> <None Include="Properties\app.manifest" />
<Content Include="Icons\betterjoyforcemu_icon.ico" /> <Content Include="Icons\betterjoyforcemu_icon.ico" />
<Content Include="hidapi.dll"> <Content Include="x86\hidapi.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="x64\hidapi.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Icons\cross.png" /> <Content Include="Icons\cross.png" />

View file

@ -516,6 +516,10 @@ namespace BetterJoyForCemu {
private static string appGuid = "1bf709e9-c133-41df-933a-c9ff3f664c7b"; // randomly-generated private static string appGuid = "1bf709e9-c133-41df-933a-c9ff3f664c7b"; // randomly-generated
static void Main(string[] args) { static void Main(string[] args) {
// Set the correct DLL for the current OS
SetupDlls();
using (Mutex mutex = new Mutex(false, "Global\\" + appGuid)) { using (Mutex mutex = new Mutex(false, "Global\\" + appGuid)) {
if (!mutex.WaitOne(0, false)) { if (!mutex.WaitOne(0, false)) {
MessageBox.Show("Instance already running.", "BetterJoy"); MessageBox.Show("Instance already running.", "BetterJoy");
@ -528,5 +532,21 @@ namespace BetterJoyForCemu {
Application.Run(form); Application.Run(form);
} }
} }
static void SetupDlls() {
const int LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000;
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
AddDllDirectory(Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
Environment.Is64BitProcess ? "x64" : "x86"
));
}
// Helper funtions to set the hidapi dll location acording to the system instruction set.
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDefaultDllDirectories(int directoryFlags);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern void AddDllDirectory(string lpPathName);
} }
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.