I’m developing an Internet Explorer ActiveX plugin using Qt, and trying to make the installer ensure the plugin is not running before continuing. A standard approach to this is to create a named mutex in the application and try to open it in the installer.
This works fine when built as a standalone .exe, but when the plugin DLL is loaded by either idc.exe (to register the server or handle the type library) or IE itself (after adding a test against argv[0] to skip CreateMutex for the idc runs), the CreateMutex call crashes.
Here’s how I’m calling it:
CreateMutex((LPSECURITY_ATTRIBUTES)MUTEX_ALL_ACCESS, FALSE, “mutex_name_here”);
Is there a reason this should fail when run within the context of an ActiveX server, but work correctly when running standalone? Is there something else I’m missing here?
The first parameter to
CreateMutex()is a pointer to a SECURITY_ATTRIBUTES structure (which contains a pointer to a security descriptor); it’s not a set of requested access rights bits, which is what you’re passing in. I’m not sure why that would work any better in a standalone application.You probably want to pass in NULL for the first parameters so the mutex gets created with a default security descriptor.
The Desired Access bits would get passed to
OpenMutex().