This is a hard question, but a good question. The following relates to the issue from the perspective of the USA.
You ask "...if the US wants to invade France, can they officially declare war by...", You have to make clear what you mean by "can". If you mean whether or not the US has the physical ability to do this, then of course they do. If you mean whether they are allowed, then this is another question. When you ask whether something is allowed, then you have to make reference to a moral code or a law that determines what is and what isn't allowed (legal). Normally each country will have laws that govern what is and what isn't legal for it's citizens to do. That hard part is how this applies to nations. There are two sides to the question. (1) What are the leaders allowed to do under their own laws, (the domestic laws) (2) what are countries as entities allowed to do? (the international laws) It sounds a bit like you are asking about the second thing. Here treaties govern what is and what isn't "legal". However, usually when someone breaks a law, other entities have the power to enforce that law and decide (judge) whether the person has broken the law. The question is: who decides whether a country has broken a treaty or an international law? And if a law is broken, what exactly can be done about it? This is hard to answer.
Consider for example the conflict in Ukraine. Here many will argue that Russia has piratically invaded Ukraine. There should be war between the nations. But Russia denies this and other world powers have done little beyond imposing sanctions. This illustrates how hard it is to deal with this question.
One question that comes up is what the purpose of international treaties are if a country can just violate them without much consequence. Pointing out two points about this. (1) If, for example, a president wants to convince his/her own congress that the country should engage in war, then it makes a stronger point if you can show how the country you want to engage has violated international trities. (2) After you have won a war, you might want to prosecute the leaders of the loosing power. Here you will stand stronger if you can make references to some international law that existed before the conflict started. This second point is illustrated in the Nuremberg principles. Here it was exactly stated that "Any person who commits an act which constitutes a crime under international law is responsible therefore and liable to punishment."
According to the US constitution "Congress shall have power to ... declare War". That means that historically Congress has the power to decide where to wage war. The War Powers Resolution says, for example, that "The President in every possible instance shall consult with Congress before introducing United States Armed Forces into hostilities ...".
Note that this doesn't mean that the US has do formally declare war before going to war. Example: The Iraq War was authorized by Congress, but there never was a formal declaration of war.
It is interesting that you ask about the timing for when the declaration should be given. The Japanese wanted to deliver their declaration of war just before the attack on Pearl Harbor. But because of issues with decrypting the message from Japan to the Japanese Embassy, the declaration wasn't delivered until after the attack.
Remember also in all of this that the winning party to a conflict, usually decides what was and wasn't legal!
One good reference for more on all of this is the report by the Congressional Research Service called "Declarations of War and Authorizations for the Use of Military Force: Historical Background and Legal Implications". Here you can see more on what I have tried (and failed?) to say above.