The lattice Boltzmann method is nowadays a common tool for solving computational fluid dynamics problems. One of the difficulties of this numerical approach is the treatment of the boundaries, because of the lack of physical intuition for the behavior of the density distribution functions close to the walls. A massive effort has been made by the scientific community to find appropriate solutions for boundaries. In this paper we present a completely generic way of treating a Dirichlet boundary for two- and three-dimensional flat walls, edges or corners, for weakly compressible flows, applicable for any lattice topology. The proposed algorithm is shown to be second-order accurate and could also be extended for compressible and thermal flows. (C) 2011 Elsevier Ltd. All rights reserved.