]> repos.lx-s.de Git - winmute.git/commitdiff
Fixed FileNotFound error during Windows startup
authorlx-s <lx-s@users.noreply.github.com>
Fri, 8 Apr 2022 05:15:48 +0000 (07:15 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Fri, 8 Apr 2022 05:15:48 +0000 (07:15 +0200)
WinMute/WinMain.cpp

index c3024ecbffcc5751425005a02f3029c8aea55c18..d2603e26fa371962cac7effae702f516d4ba2e78 100644 (file)
@@ -35,6 +35,20 @@ POSSIBILITY OF SUCH DAMAGE.
 
 HINSTANCE hglobInstance;
 
+static bool SetWorkingDirectory()
+{
+   char wmFileName[MAX_PATH + 1];
+   if (GetModuleFileNameA(NULL, wmFileName, ARRAY_SIZE(wmFileName)) > 0) {
+      char* p = strrchr(wmFileName, '\\');
+      if (p != NULL) {
+         *(p+1) = '\0';
+         SetCurrentDirectoryA(wmFileName);
+         return true;
+      }
+   }
+   return false;
+}
+
 int WINAPI wWinMain(_In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE,
    _In_ PWSTR,
@@ -58,6 +72,8 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance,
       return FALSE;
    }
 
+   SetWorkingDirectory();
+
    hglobInstance = hInstance;
 
    HeapSetInformation(nullptr, HeapEnableTerminationOnCorruption, nullptr, 0);