Reputation: 6911
I've just discovered Desktops, and I would like to improve support for it in my application.
I'm using a mutex to prevent multiple instances of the application from running, but I would like to allow to start additional instances if they are launched on a different desktop.
Is it possible to do with a mutex? As far as I know, there are only global and local (per-user) mutex, but no per-desktop mutexes.
Any ideas?
Upvotes: 0
Views: 108
Reputation: 16904
Name the mutex
myCompanyName_myApplicationName_myApplicationVersion_desktopName
Applications running on different desktops will then be looking at different mutexes.
You can get the desktop name like this, though you might want to add some error checking:
wchar_t buffer[256];
DWORD length;
// This desktop handle does not need closing
HANDLE hDesktop = GetThreadDesktop(GetCurrentThreadId());
BOOL succeeded = GetUserObjectInformation(hDesktop, UOI_NAME, buffer, sizeof(buffer), &length);
// if succeeded then desktop name is in buffer
Upvotes: 1