Skip to content

Commit

Permalink
refactor: use message box for errors in DLL loading
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jul 21, 2024
1 parent 49ec2de commit d267cbf
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/endstone_runtime/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID /*reserved*/)
if (LoadLibraryA(dll_path) == nullptr) {
DWORD error_code = GetLastError();
LPVOID buffer;
DWORD len = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr,
error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPTSTR>(&buffer), 0, nullptr);

if (len) {
printf("Failed to load DLL: %s, Error code: %lu, Message: %s\n", dll_path, error_code,
static_cast<LPCSTR>(buffer));
LocalFree(buffer);
}
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPTSTR>(&buffer), 0, nullptr);

char message[512];
sprintf(message, "LoadLibrary failed to load %s with error %lu: %s", dll_path, error_code,
reinterpret_cast<LPCSTR>(buffer));
MessageBoxA(nullptr, message, "Error", MB_OK | MB_ICONERROR);
LocalFree(buffer);
ExitProcess(error_code);
}
break;
Expand Down

0 comments on commit d267cbf

Please sign in to comment.