Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call WinAPI function SetDllDirectory() in Delphi?

I would like to prevent loading of malicious DLLs that may be possible through access of the current working directory as described in http://msdn.microsoft.com/en-us/library/ff919712(VS.85).aspx

The solution implemented in our C++ apps was to make a WinAPI call to SetDllDirectory(""), which would effectively remove the current working directory from the Windows DLL loading search path. However, it seems this solution is not available for our Delphi apps because the SetDllDirectory() function doesn't exist.

Is there an equivalent call in Delphi that does the same thing as SetDllDirectory("")? Thanks!

like image 968
Stephen Avatar asked Oct 28 '10 21:10

Stephen


1 Answers

This should do the trick:

function SetDllDirectory(lpPathName:PWideChar): Bool; stdcall; external 'kernel32.dll' name 'SetDllDirectoryW';
like image 164
Jens Mühlenhoff Avatar answered Sep 28 '22 09:09

Jens Mühlenhoff