What should I do about a gap between hardwood and drywall?
Killing the ants is one thing, and the comments from others are good.  However, you need to fix the root cause of the problem, which is hole that you can see daylight from.  Spray foam will only deter them for a while.  You should NEVER be able to see daylight through a wall from the inside of a home.  I would take a good look outside and see how much of a gap existed before the foamed it.  You may have to remove the siding to see everything, but I suspect the exterior wall may need to be patched.