Add reason when failing loading a windows dll (#3592)
This commit is contained in:
parent
9c6feafd47
commit
9b6d9f86ac
1 changed files with 28 additions and 18 deletions
|
|
@ -747,16 +747,9 @@ RZ_API bool rz_sys_mkdirp(const char *dir) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
RZ_API void rz_sys_perror_str(const char *fun) {
|
#if __WINDOWS__
|
||||||
#if __UNIX__
|
static char *sys_windows_error_msg(DWORD dw) {
|
||||||
#pragma push_macro("perror")
|
|
||||||
#undef perror
|
|
||||||
perror(fun);
|
|
||||||
#pragma pop_macro("perror")
|
|
||||||
#elif __WINDOWS__
|
|
||||||
LPTSTR lpMsgBuf;
|
LPTSTR lpMsgBuf;
|
||||||
DWORD dw = GetLastError();
|
|
||||||
|
|
||||||
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
|
@ -765,17 +758,31 @@ RZ_API void rz_sys_perror_str(const char *fun) {
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
(LPTSTR)&lpMsgBuf,
|
(LPTSTR)&lpMsgBuf,
|
||||||
0, NULL)) {
|
0, NULL)) {
|
||||||
char *err = rz_sys_conv_win_to_utf8(lpMsgBuf);
|
char *message = rz_sys_conv_win_to_utf8(lpMsgBuf);
|
||||||
if (err) {
|
|
||||||
eprintf("%s: (%#lx) %s%s", fun, dw, err,
|
|
||||||
rz_str_endswith(err, "\n") ? "" : "\n");
|
|
||||||
free(err);
|
|
||||||
}
|
|
||||||
LocalFree(lpMsgBuf);
|
LocalFree(lpMsgBuf);
|
||||||
|
rz_str_trim_tail(message);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif /* __WINDOWS__ */
|
||||||
|
|
||||||
|
RZ_API void rz_sys_perror_str(const char *fun) {
|
||||||
|
#if __UNIX__
|
||||||
|
#pragma push_macro("perror")
|
||||||
|
#undef perror
|
||||||
|
perror(fun);
|
||||||
|
#pragma pop_macro("perror")
|
||||||
|
#elif __WINDOWS__
|
||||||
|
DWORD dw = GetLastError();
|
||||||
|
char *err = sys_windows_error_msg(dw);
|
||||||
|
if (err) {
|
||||||
|
eprintf("%s: (%#lx) %s\n", fun, dw, err);
|
||||||
|
free(err);
|
||||||
} else {
|
} else {
|
||||||
eprintf("%s\n", fun);
|
eprintf("%s\n", fun);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* __WINDOWS__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
RZ_API bool rz_sys_arch_match(const char *archstr, const char *arch) {
|
RZ_API bool rz_sys_arch_match(const char *archstr, const char *arch) {
|
||||||
|
|
@ -1973,7 +1980,7 @@ RZ_API void *rz_sys_dlopen(RZ_NULLABLE const char *libname) {
|
||||||
} else {
|
} else {
|
||||||
libname_ = calloc(MAX_PATH, sizeof(TCHAR));
|
libname_ = calloc(MAX_PATH, sizeof(TCHAR));
|
||||||
if (!libname_) {
|
if (!libname_) {
|
||||||
RZ_LOG_ERROR("lib/rz_sys_dlopen: Failed to allocate memory.\n");
|
RZ_LOG_ERROR("rz_sys_dlopen: failed to allocate memory.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!GetModuleFileName(NULL, libname_, MAX_PATH)) {
|
if (!GetModuleFileName(NULL, libname_, MAX_PATH)) {
|
||||||
|
|
@ -1983,7 +1990,10 @@ RZ_API void *rz_sys_dlopen(RZ_NULLABLE const char *libname) {
|
||||||
ret = LoadLibrary(libname_);
|
ret = LoadLibrary(libname_);
|
||||||
free(libname_);
|
free(libname_);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
RZ_LOG_ERROR("rz_sys_dlopen: error: %s\n", libname);
|
DWORD dw = GetLastError();
|
||||||
|
char *err = sys_windows_error_msg(dw);
|
||||||
|
RZ_LOG_ERROR("rz_sys_dlopen: error: %s (%s)\n", libname, err ? err : "unknown");
|
||||||
|
free(err);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue