On a direct method for the determination of an exact invariant for the time-dependent harmonic oscillator