Some types of gelatin are of vegetable origin, and there is nothing wrong with using this or eating foods that contain it.
Some types of gelatin are of animal origin, and this is subject to further discussion. Whatever the case, there is nothing wrong with eating foods that contain it because even if it comes from animals that have not been slaughtered properly or other haraam sources, it has been transformed into another substance that has different characteristics.
See the answer to question no. 97541.
We have not been able to find out whether what you say is true about carmine and its being derived from female ants. If we assume that it is indeed the case, if the sweet is not harmful then there is nothing wrong with eating it, because of what was mentioned above about the haraam substance being transformed into a different substance.
With regard to lice, there is a difference of opinion as to whether they are naajis. Some of the fuqaha' say that they are naajis (impure) because they contain blood and their food is blood. Some of them say that they are taahir (pure) because they are likened to flies. But there is consensus that it is haraam to eat them.
Al-Duraymi (may Allah have mercy on him) said: It is haraam to eat lice according to consensus. End quote from Hayaat al-Haywaan al-Kubra, 2/118.
It is haraam to eat lice just as it is haraam to eat maytah (meat that was not slaughtered properly) or drink alcohol. But if they have been turned into another substance by means of some treatment, then there is nothing wrong with eating that substance, as explained above.
It should be noted that the basic principle with regard to these foods and drinks is that they are permissible, because it cannot be said that any of them are haraam on the basis of speculation. Similarly it cannot be said that most of the sweets contain gelatin, because this is contrary to reality. If a person wants to avoid things containing gelatin or carmine, he will find plenty of other alternatives in other types of sweets.
And Allah knows best.