Preventing multiple instances of COM singleton???
-
Hi I am building a out of proc COM Server, which would be registered as service. I want my server to be a singleton, so I have declared DELCARE_CLASSFACTORY_SINGLETON in my coclass. My server startup code RegisterClassObjects with REGCLS_MULTIPLEUSE flag. However, it is possible to launch 2 instances of my server process; one that is launched by the service manager and running under the system account; the second one can be launched from the current user's account. How do I prevent mutiple instances of my COM server, irrespective of the user accounts? Thanks in advance Vivek Ragunathan
http://vivekragunathan.spaces.live.com
Programming is an art. Code is a poem
-
Hi I am building a out of proc COM Server, which would be registered as service. I want my server to be a singleton, so I have declared DELCARE_CLASSFACTORY_SINGLETON in my coclass. My server startup code RegisterClassObjects with REGCLS_MULTIPLEUSE flag. However, it is possible to launch 2 instances of my server process; one that is launched by the service manager and running under the system account; the second one can be launched from the current user's account. How do I prevent mutiple instances of my COM server, irrespective of the user accounts? Thanks in advance Vivek Ragunathan
http://vivekragunathan.spaces.live.com
Programming is an art. Code is a poem
You can create a global named mutex to prevent running multiple instances of an EXE across multiple use accounts. Prefix the mutex name with
"Global\"
Use CreateMutex[^] to create the object. If calling GetLastError[^] after this returnsERROR_ALREADY_EXISTS
the EXE can quit itself using PostQuitMessage[^].«_Superman_» I love work. It gives me something to do between weekends.
-
You can create a global named mutex to prevent running multiple instances of an EXE across multiple use accounts. Prefix the mutex name with
"Global\"
Use CreateMutex[^] to create the object. If calling GetLastError[^] after this returnsERROR_ALREADY_EXISTS
the EXE can quit itself using PostQuitMessage[^].«_Superman_» I love work. It gives me something to do between weekends.
Thanks. That is one way to solve the problem. But what I am really looking for is a way that COM infrastructure would take care of. What this means is I should not report error to the user, instead return the reference of the already created COM object. If the COM server is launched as service and all users connect to it using CoCreateInstance, they get the same reference. But when the COM server is launched using the current user account, things are screwed up as a second instance is created. Instead COM should not create the second instance, instead return the reference of the COM object hosted in the service. Thanks
http://vivekragunathan.spaces.live.com
Programming is an art. Code is a poem