Heartworms only reside in the area of the dogs heart that surround the blood vessels and do not come out in a dogs poop.
If your dog has worms coming out in it's poop it's a different worm.
The worms in your dogs poop are likely hookworms. When a dog has heartworms they'll have signs such as lethargy and coughing.