The space of all weakly holomorphic modular forms and the space of all
holomorphic period functions of a fixed weight for the modular group are realized
as locally convex topological vector spaces that are topologically dual to
each other. This framework is used to study the kernel and range of a linear
differential operator that preserves modularity and to define and describe
its adjoint. The main results are an index formula for such a differential
operator that is holomorphic at infinity and the identification of the cokernel of
the operator as a cohomology group of the modular group acting on the
kernel.