UPD: mbLoadLibraryEx function

This commit is contained in:
Alexander Koblov 2025-04-18 22:59:05 +03:00
commit 2dd9817eb9

View file

@ -1898,35 +1898,28 @@ const
PATH_ENV = 'PATH';
var
APath: String;
FullName: String;
usName: UnicodeString;
begin
FullName:= Name;
usName:= CeUtf8ToUtf16(Name);
if GetPathType(Name) = ptNone then
begin
FindInSystemPath(FullName);
end;
usName:= CeUtf8ToUtf16(FullName);
if CheckWin32Version(10)then
if CheckWin32Version(10) or (GetProcAddress(GetModuleHandleW(Kernel32), 'AddDllDirectory') <> nil) then
begin
Result:= LoadLibraryExW(PWideChar(usName), 0, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR or LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
end
else if CheckWin32Version(6) then
begin
SetDllDirectoryW(PWideChar(ExtractFileDir(usName)));
try
Result:= LoadLibraryW(PWideChar(usName));
finally
SetDllDirectoryW(nil);
end;
end
else begin
APath:= mbGetEnvironmentVariable(PATH_ENV);
try
mbSetEnvironmentVariable(PATH_ENV, ExtractFileDir(Name));
Result:= LoadLibraryW(PWideChar(usName));
if GetPathType(Name) <> ptAbsolute then
SetDllDirectoryW(PWideChar(''))
else begin
SetDllDirectoryW(PWideChar(ExtractFileDir(usName)));
end;
try
SetEnvironmentVariableW(PATH_ENV, nil);
Result:= LoadLibraryW(PWideChar(usName));
finally
SetDllDirectoryW(nil);
end;
finally
mbSetEnvironmentVariable(PATH_ENV, APath);
end;