For a non-negative r.v. $X$ s.t. $\mathbb E{X}<\infty$, and $g$ s.t. $||g||_\infty$ and $||g'||_\infty$ are both $<\infty$ (where $||\cdot ||_\infty$ is the essential supremum), we have that $$\begin{aligned} \int_0^\infty g'(x) P(X>x) d P &= \int_0^\infty \int_\Omega g'(x) 1_{[X>x]} dP dx = \int_\Omega \int_0^\infty g'(x) 1_{[X>x]} dx dP \\ &= \int_\Omega \int_0^X g'(x) dx dP = \int_\Omega g(X) - g(0) d P = \mathbb{E}(g(X))-g(0) \\ \end{aligned}$$ where the integral interchange is justified because $$\int_\Omega \int_0^\infty |g' 1_{[X>x]}|dxdP \leq \int_\Omega \int_0^X ||g'||_\infty dx dP = ||g'||_\infty \mathbb E{X} < \infty$$ In this link: How to prove $E[g(x)] = \int_0^\infty g'(x)S(x) dx$, one of the answers has a formula for general r.v.'s $X$ (i.e. not just non-negative one), but having to go to density functions and integrating by parts (and perhaps some extra conditions on $g$). Is there a proof of the general case without resorting to density functions, like my proof above?
Second, is there a more general formulation if we want $\mathbb{E}[g(X)1_{[a<X\leq b]}]$ instead?