WinDirs...
Do two things.
-
Simplify
WinDirs
(and fix certain nonfatal instances of wrong checks of function pointers).
-
1.1. According to this comment and the issue it refers to, it loads
shell32.dll
the complicated way to prevent loading wrongshell32.dll
accidentally or maliciously placed into the application directory. Honestly, the threat of spoofing wrongshell32.dll
can be ignored just as the threat of spoofing wrongapp.exe
, but it doesn’t even exist in the first place because of a Windows feature named “Known DLLs”. See this StackOverflow answer and this ancient article. -
1.2. I don’t think error checking makes sense. System without
shell32.dll
etc. is corrupt past the point of being able to correctly run something that needs Windows special directories. Moreover, it already was non-existent: condition
if (@_SHGetFolderPathW = nil) and (@_SHGetKnownFolderPathW = nil) then
raise Exception.Create('Could not locate '+SSHGetFolderPathW+' / '+SSHGetKnownFolderPathW+' functions');
is not met even if both function pointers are nil
s. (Exercise: explain why.) In a similar way, there’s no point in falling back to SHGetKnownFolderPath
if SHGetFolderPath
does not exist because it’s not like Microsoft likes removing functions. In a similar way, the code if CSIDLtoFOLDERID[I].FOLDERID <> nil then
does not make sense at all.
-
Delay-load
ole32.dll
(the unit was already delaying the loading ofshell32.dll
, though not for the performance but because it was concerned about not finding the functions). This makes the Windows version of the Free Pascal itself avoid loadingole32.dll
unless actually required (namely, unless Windows special folders occur in paths, which usually does not happen). (Advertisement: think also of this MR.)