Re: [GD-Windows] Limiting to one instance
Brought to you by:
vexxed72
From: Alen L. <ale...@cr...> - 2006-08-15 08:13:27
|
> I remember at an old company one genius tried to prevent multiple instances > of an app by binding a port, and was then surprised when it failed for > pretty much everyone who was running a firewall! Actually, it's not such a weird idea. Some applications rely on IP ports as a simple yet very portable IPC mechanism. Firewalls should really know better, by handling 127.0.0.1 specifically by default. But apparently even the best in class don't. Btw, in my book, even using a named mutex in that way is a bit hacky because you are relying on error. But what can we do, when there's no real API intended for that purpose. Personally, I've been using FindWindow(xyz, NULL) to find a main window by class name. Same principle (with same weaknesses as a named mutex), but doesn't require an extra object creation, as you probably already have a window, and you can use this to test even for foreign applications, because it doesn't require access to the code of the tested application. A nice side effect is that once you have the window, you can report messages like "Cannot start, please close ABCD application first", where you get the ABCD from the application's main window caption. Cheers, Alen |