When you have a black market it is not because the exchange rate is unreal, but because people cannot get hard currency legally (if they could, why wouldn't they change their money at the bank, at the better rate).
Governments have many costs to entities operating abroad: from upkeep of ambassies and missions, to the purchase of supplies and weapons for the military, including -if the economy is more or less directed- supplies needed to keep the enterprises running.
To purchase them, it is asked to provide hard (stable) currency, usually US$.
Let's use US$ as any hard currency, and L for the local currency.
Now, how would a government get US$? If things are ok, as everyone would do: exchanging its own currency. They go to a bank, offer a sum in L, and retire an amount of US$.
But of course, to people to be interested in L, it must be useful to get something in exchange. If the country produces pineapples and people abroad want pineapples, then people will change US$ for L and the bank will have the US$ available for the government (or anybody) to exchange it back for L.
If people are not interested in pineapples or the harvest fails, then people will not be interested in exchanging US$ for L.
What happens if people is no interested in L? Well, the government still needs US$, and now it remembers that, after all, it is the government, and begins pushing the buttons the government has.
One of these buttons is that it can force people in the country negotiating with US$ to change them for local currency at allowed banks.
People changing US$ to L will get a rate, people changing L to US$ will get an astronomical worse rate or (most probably) will not be allowed to change unless they can convince a government official that they intend to import something important (raw materials, medicines, machinery).
This provides the government with a steady supply of US$. A side benefit is that usually it does not affect the poorer people, since they tend to consume cheaper, locally produce items1. Another side benefit is that it makes imports more difficult.
Of course, once people notices that tourists and the like are given, say 10L for US$, and local people have to pay 100L for US$ (or are left with their Ls in the hand without having option to legally buy US$), the black market appears. Offer 20/30L for $ to the tourist, sell each US$ for 60L, profit!
Why not just allow free market? Well, if the country is in a dire economic situation (and the lack of exports is a good signal of it), everyone who has L will try to get US$ as soon as possible. This will lead only to further depreciation of L(and more selling pressure), meaning that the government (like everyone else) would need to pay still more Ls to get the same US$.
1An exception happens to be if the country imports its energy sources, since the price of energy influences the price of almost everything else.