First let's take a look at a diagram for reference:

The procedure for calculating H1 and H2 is as follows:
- Compute the intersection, if any, between the ray
R and the line
segment P1P2. We're only interested in intersections that lie
within the interior of P1P2. Similarly for P3P4. The points P1 to P4 can be calculated easily from the circle centers, C1 and C2, and some vector math. E.g. P1 = C1 + r*nC, where nC is the normal (CCW) of the unit vector from C1 to C2. This
answer on SO provides the necessary math to determine if an
intersection exists between two line segments and, if so, calculate the parameter h, such
that H=R1+h(R2-R1), where H is an intersection point. This step can produce 0, 1, or 2 valid h values, depending on whether the ray intersects neither, one, or both of P1P2, P3P4.
- Compute the intersection points, if any, between the ray and each of the 2
circles. Again, an SO answer provides the necessary math for
ray to circle intersection. Each circle can produce 0, 1, or 2
intersections, again represented parametrically.
- If no valid
h values were generated from steps 1 & 2 then the ray does not intersect the capsule. Otherwise, calculate hMin and hMax, the min and max parameter values of all valid
intersections identified in steps 1 & 2. Note that it's possible that hMin==hMax, in the case where the ray is tangent to one of the circles and does not intersect P1P2 or P3P4. The required intersection point(s) can now be calculated as H1=R1+hMin(R2-R1) and H2=R1+hMax(R2-R1).
I'm afraid my language of choice is Java rather than C++, but hopefully you'll find the code (IDEOne) I put together helpful as a reference. Please be aware that no effort was put it to handle robustness issues resulting from the rounding of double values during calculations.