Commit de711e1685277f71ae81cfc1f835b2c7b8ac3056

pionere 2022-04-12T10:32:43

simplify SDL_GetBasePath on windows - use GetModuleFileName directly (as recommended)

diff --git a/src/filesystem/windows/SDL_sysfilesystem.c b/src/filesystem/windows/SDL_sysfilesystem.c
index d50fb51..d2f6185 100644
--- a/src/filesystem/windows/SDL_sysfilesystem.c
+++ b/src/filesystem/windows/SDL_sysfilesystem.c
@@ -35,39 +35,23 @@
 char *
 SDL_GetBasePath(void)
 {
-    typedef DWORD (WINAPI *GetModuleFileNameExW_t)(HANDLE, HMODULE, LPWSTR, DWORD);
-    GetModuleFileNameExW_t pGetModuleFileNameExW;
     DWORD buflen = 128;
     WCHAR *path = NULL;
-    HANDLE psapi = LoadLibrary(TEXT("psapi.dll"));
     char *retval = NULL;
     DWORD len = 0;
     int i;
 
-    if (!psapi) {
-        WIN_SetError("Couldn't load psapi.dll");
-        return NULL;
-    }
-
-    pGetModuleFileNameExW = (GetModuleFileNameExW_t)GetProcAddress(psapi, "GetModuleFileNameExW");
-    if (!pGetModuleFileNameExW) {
-        WIN_SetError("Couldn't find GetModuleFileNameExW");
-        FreeLibrary(psapi);
-        return NULL;
-    }
-
     while (SDL_TRUE) {
         void *ptr = SDL_realloc(path, buflen * sizeof (WCHAR));
         if (!ptr) {
             SDL_free(path);
-            FreeLibrary(psapi);
             SDL_OutOfMemory();
             return NULL;
         }
 
         path = (WCHAR *) ptr;
 
-        len = pGetModuleFileNameExW(GetCurrentProcess(), NULL, path, buflen);
+        len = GetModuleFileName(NULL, path, buflen);
         /* if it truncated, then len >= buflen - 1 */
         /* if there was enough room (or failure), len < buflen - 1 */
         if (len < buflen - 1) {
@@ -78,8 +62,6 @@ SDL_GetBasePath(void)
         buflen *= 2;
     }
 
-    FreeLibrary(psapi);
-
     if (len == 0) {
         SDL_free(path);
         WIN_SetError("Couldn't locate our .exe");