Adding DirectX directories to Visual Studio
Sometimes when you install the DirectX SDK, it doesn't properly add the directories to Visual Studio, so VS can't find the DirectX headers and library files. The most common symptom of this is the compile error "Cannot open include file: 'd3d9.h': No such file or directory".
To add the headers and library files to Visual Studio (2005 or 2008, they're both the same), go to the Tools menu -> Options, then go to Projects and Solutions -> VC++ Directories. First, make sure the "Show directories for:" droplist in the top right is set to "Include files", and add the path to the DirectX SDK/Include directory, and make sure it's at the top of the list by clicking the black up arrow icon:
Next, change the "Show directories for:" droplist to "Library files", and add the path to the DirectX SDK/Lib/x86 directory. The additional x86 directory is important here, and if you miss it out, Visual Studio won't be able to find the library files:
If you're building for x64, then you'll want to change the "Platform" drop list to "x64" and add the DirectX SDK/Lib/x64 directory instead. If you're not sure what you want, then you probably want Win32 and the x86 directory.
After you've added those two directories, click "OK", then hit F5 to build and run your code again.