Skip to content

Commit 43786c1

Browse files
shukenmgShuken
andauthored
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>
1 parent 06edcb1 commit 43786c1

5 files changed

Lines changed: 24 additions & 1 deletion

File tree

BetterJoyForCemu/BetterJoy.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@
236236
<Content Include="Icons\snes.png" />
237237
<None Include="Properties\app.manifest" />
238238
<Content Include="Icons\betterjoyforcemu_icon.ico" />
239-
<Content Include="hidapi.dll">
239+
<Content Include="x86\hidapi.dll">
240+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
241+
</Content>
242+
<Content Include="x64\hidapi.dll">
240243
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
241244
</Content>
242245
<Content Include="Icons\cross.png" />

BetterJoyForCemu/Program.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ public static void Stop() {
516516

517517
private static string appGuid = "1bf709e9-c133-41df-933a-c9ff3f664c7b"; // randomly-generated
518518
static void Main(string[] args) {
519+
520+
// Set the correct DLL for the current OS
521+
SetupDlls();
522+
519523
using (Mutex mutex = new Mutex(false, "Global\\" + appGuid)) {
520524
if (!mutex.WaitOne(0, false)) {
521525
MessageBox.Show("Instance already running.", "BetterJoy");
@@ -528,5 +532,21 @@ static void Main(string[] args) {
528532
Application.Run(form);
529533
}
530534
}
535+
536+
static void SetupDlls() {
537+
const int LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000;
538+
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
539+
AddDllDirectory(Path.Combine(
540+
AppDomain.CurrentDomain.BaseDirectory,
541+
Environment.Is64BitProcess ? "x64" : "x86"
542+
));
543+
}
544+
545+
// Helper funtions to set the hidapi dll location acording to the system instruction set.
546+
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
547+
[return: MarshalAs(UnmanagedType.Bool)]
548+
static extern bool SetDefaultDllDirectories(int directoryFlags);
549+
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
550+
static extern void AddDllDirectory(string lpPathName);
531551
}
532552
}

BetterJoyForCemu/hidapi.dll

-19 KB
Binary file not shown.

BetterJoyForCemu/x64/hidapi.dll

18 KB
Binary file not shown.

BetterJoyForCemu/x86/hidapi.dll

14 KB
Binary file not shown.

0 commit comments

Comments
 (0)