The d3dx9_27.dll can be downloaded here.

(Windows 32 bit version only) Once downloaded, double click on the zip file and extract the d3dx9_27.dll file to your Windows\System32 directory.
(Windows 64 bit version only) Once downloaded, double click on the zip file and extract the d3dx9_27.dll file to your C:\Windows\SysWOW64 directory.

To run Stronghold 2, Microsoft DirectX 9.0c or higher must be installed on your computer. If you have an older version of DirectX installed on your system, the Stronghold 2 installation will upgrade you to the required DirectX version. If you are having problems installing DirectX, you can download it from the Microsoft website here.