FIX: Save last error

This commit is contained in:
Alexander Koblov 2023-11-28 19:51:34 +03:00
commit 4b6bfe3345

View file

@ -1801,16 +1801,19 @@ end;
function mbLoadLibrary(const Name: String): TLibHandle;
{$IFDEF MSWINDOWS}
var
dwErrCode: DWORD;
sRememberPath: String;
begin
try
//Some plugins using DLL(s) in their directory are loaded correctly only if "CurrentDir" is poining their location.
//Also, TC switch "CurrentDir" to their directory when loading them. So let's do the same.
sRememberPath:=GetCurrentDir;
SetCurrentDir(ExcludeTrailingPathDelimiter(ExtractFilePath(Name)));
// Some plugins using DLL(s) in their directory are loaded correctly only if "CurrentDir" is poining their location.
// Also, TC switch "CurrentDir" to their directory when loading them. So let's do the same.
sRememberPath:= GetCurrentDir;
SetCurrentDir(ExtractFileDir(Name));
Result:= LoadLibraryW(PWideChar(CeUtf8ToUtf16(Name)));
dwErrCode:= GetLastError;
finally
SetCurrentDir(sRememberPath);
SetLastError(dwErrCode);
end;
end;
{$ELSE}