@@ -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}
0 commit comments