Basically, DIRECTX is an instruction set, sort of like drivers, to allow your graphics cards (drivers) interact THROUGH Windows to talk to the game.
The game may call certain procedures (code) that depend on DIRECTX. Just like any other software, DX 9 will act differently from DX 8 etc.
It gets a bit more in depth. For example, DX will work as a network gaming component, allowing correct transfer of data between systems. Sound is also covered.