simplify SDL_GetBasePath on windows - use GetModuleFileName directly (as recommended)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
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");