This commit is contained in:
blueloveTH 2023-07-15 16:00:57 +08:00
parent 89ec12cada
commit c55bb4b8af

View File

@ -12,29 +12,23 @@ static dylib_entry_t load_dylib(const char* path){
auto p = std::filesystem::absolute(path, ec); auto p = std::filesystem::absolute(path, ec);
if(ec) return nullptr; if(ec) return nullptr;
HMODULE handle = LoadLibraryA(p.string().c_str()); HMODULE handle = LoadLibraryA(p.string().c_str());
// get last error if(!handle){
// Get the last error code
SetErrorMode(SEM_FAILCRITICALERRORS);
DWORD errorCode = GetLastError(); DWORD errorCode = GetLastError();
// Convert the error code to text // Convert the error code to text
LPSTR errorMessage = nullptr; LPSTR errorMessage = nullptr;
FormatMessageA( FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, nullptr,
errorCode, errorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(LPSTR)&errorMessage, (LPSTR)&errorMessage,
0, 0,
nullptr nullptr
); );
// Print the error message to stdout
printf("%lu: %s\n", errorCode, errorMessage); printf("%lu: %s\n", errorCode, errorMessage);
// Free the message buffer
LocalFree(errorMessage); LocalFree(errorMessage);
if(!handle) return nullptr; return nullptr;
}
return (dylib_entry_t)GetProcAddress(handle, "platform_module__init__"); return (dylib_entry_t)GetProcAddress(handle, "platform_module__init__");
} }
#elif PK_SUPPORT_DYLIB == 2 #elif PK_SUPPORT_DYLIB == 2