The effective interaction between two planar walls immersed in a fluid is investigated by use of density functional theory in the supercritical region of the phase diagram. A hard core Yukawa model of fluid is studied with special attention to the critical region. To achieve this goal a formulation of the weighted density approximation coupled with the hierarchical reference theory, able to deal with critical long wavelength fluctuations, is put forward and compared with other approaches. The effective interaction between the walls is seen to change character on lowering the temperature: The strong oscillations induced by layering of the molecules, typical of the depletion mechanism in hard core systems, are gradually smoothed and, close to the critical point, a long range attractive tail emerges leading to a scaling form which agrees with the expectations based on the critical Casimir effect. Strong corrections to scaling are seen to affect the results up to very small reduced temperatures. By use of the Derjaguin approximation, this investigation has natural implications for the aggregation of colloidal particles in critical solvents.