Thanks for the details. So basically, you do not need the "synchronization" aspect of a mutex, just the "global name" aspect to check for exists / doesn't-exist check. I have used two methods for exactly this problem. Both methods "reset" when the image exits because Windows cleans up the objects. One is to use "named pipes". This method has been suggested by other people in Code Project. You create a pipe with a known name agreed upon by the two processes. When you say "gui uses server", I assume you communicate in some way, you might even use pipes. I prefer this method when I need to also communicate between the processes as it provides for both a "single server instance" and the "interprocess communication". Here's a routine I use to create an "inbound" pipe (the server code) in such a way as there will be only 1 instance. The error INVALID_HANDLE_VALUE indicates that you cannot create the pipe which is taken to mean that the pipe is already in use. I've "scrubbed" this a little to remove things I cannot share with you.
#ifndef FILE_FLAG_FIRST_PIPE_INSTANCE
#define FILE_FLAG_FIRST_PIPE_INSTANCE 0x00080000 // make VC 6.0 happy
#endif
#define RTLOCALIPC_WIN_SDDL \
SDDL_DACL SDDL_DELIMINATOR \
SDDL_ACE_BEGIN SDDL_ACCESS_ALLOWED ";;" SDDL_GENERIC_ALL ";;;" SDDL_NETWORK SDDL_ACE_END \
SDDL_ACE_BEGIN SDDL_ACCESS_ALLOWED ";;" SDDL_GENERIC_ALL ";;;" SDDL_EVERYONE SDDL_ACE_END \
SDDL_ACE_BEGIN SDDL_ACCESS_ALLOWED ";;" SDDL_FILE_ALL ";;;" SDDL_LOCAL_SYSTEM SDDL_ACE_END
// Create an inbound pipe with a known name (e.g., "0CE7CCB0-6AB2-4c55-89C4-8EE95E759C30" from GUID tool)
HANDLE CreateInboundPipe(CString PName, bool first)
{
CString ts;
SECURITY_ATTRIBUTES *SecAttrs = NULL;
DWORD dwOpenMode;
DWORD dwPipeMode;
// The following is conditionalized to allow old VC++ 6.0 to compile this module. However,
// programs build with VC++ 6.0 should \*not\* be creating new inbound pipes. Those programs
// should be using VS 2005 or later. This is because the Security requirements for Vista
// makes us use a security attribute that excludes the network (local IPC only) and you need
// VS 2005 or later for that to work properly. VC++ 6.0 clients should only open outbound pipes.
PSECURITY\_DESCRIPTOR pSecDesc = NULL;
ConvertStringSecurityDescriptorToSecurityDescriptor(RTLOCALIPC\_WIN\_SDDL, SDDL\_REVISION\_1, &pSecDesc, NULL);
SecAttrs = (SECURITY\_ATTRIBUTES \*)malloc(sizeof(SECURITY\_ATTRIBUTES));
SecAttrs->nLength = sizeof(SECURITY\_ATTRIBUTES);
SecAt