A method is developed for solving the problems of bound, scattering, and resonant states of charge carriers in semiconductor nanostructures within the effective-mass envelope-function approach. On each interval of the effective-mass constancy, the Schr\odinger equation is replaced by an equivalent system of linear first-order differential equations whose solutions are used to construct the modified transfer matrix by matching them via the Ben-Daniel--Duke--Bastard procedure at the points of the effective mass discontinuity. In contrast to the traditional transfer matrix theory where the potential energy is approximated by a sequence of rectangular steps, the proposed method is able to deal with an arbitrary potential profile directly and in an exact way, i.e., without resorting to the plane-wave approximation at each step. Therefore, the number of factors in the total transfer matrix is always equal to the number of intervals where the effective mass remains constant, no matter how complicated the potential profile. After the transfer matrix is obtained, the Jost matrix that totally determines the interaction properties, can be easily constructed. Zeros of its determinant in the complex energy plane correspond to bound states and resonances. Within the proposed method there is a natural way of inclusion of the long-range potential tails that may arise, for example, due to the charge accumulation. The pure Coulomb tails are taken into account in an exact way, i.e., analytically. An additional feature of the proposed method is the possibility of calculating not only the total widths of resonances but their partial widths as well. The effectiveness and accuracy of the method are demonstrated by several numerical examples.