Multiple instances of the same application

Hi. Can you tell me some practical uses (if they are) and advantages of using multiple instances in the same application (like creating two windows, each one having its own instance - if it is possible)? Thanks!
It is as simple as running the same executable twice. It has numerous advantages. For example, you can have multiple Notepads open to handle multiple text files. You can have multiple test executables running to simulate multiple clients to a server application. And the list goes on and on.
O.K. So it's like clicking on the same executable twice and create two instances of the program. Anyway, there are application that are not allowed to be opened twice. How do you enable this restriction?
Thanks!
To enable the restriction you create a named mutex using CreateMutex() and a very unique name that will not collide with mutex names of other applications (usually a GUID suffices). Verify that the function call succeeds and then check the value of GetLastError(). If it is ERROR_ALREADY_EXISTS then a previous instance of your application is running and you should stop execution of this one.

When your application exits, close the mutex handle using CloseHandle().
Mmmmmmmm. That works. Thanks!
Topic archived. No new replies allowed.