1
0
mirror of https://gitea.tendokyu.moe/Dniel97/segatools.git synced 2024-11-14 08:07:37 +01:00
segatools-dniel97/util/lib.c

30 lines
557 B
C

#include <windows.h>
#include <stdbool.h>
wchar_t *module_file_name(HMODULE module)
{
size_t buf_len;
DWORD len;
wchar_t *buf;
buf_len = MAX_PATH;
buf = malloc(buf_len * sizeof(*buf));
while (true) {
len = GetModuleFileNameW(module, buf, buf_len);
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
buf_len = len;
buf = realloc(buf, buf_len * sizeof(*buf));
break;
}
buf_len *= 2;
buf = realloc(buf, buf_len * sizeof(*buf));
}
return buf;
}