Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Preventing multiple instances of COM singleton???

Preventing multiple instances of COM singleton???

Scheduled Pinned Locked Moved ATL / WTL / STL
questioncomsysadmin
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kb boxer
    wrote on last edited by
    #1

    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

    _ 1 Reply Last reply
    0
    • K kb boxer

      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

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      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 returns ERROR_ALREADY_EXISTS the EXE can quit itself using PostQuitMessage[^].

      «_Superman_» I love work. It gives me something to do between weekends.

      K 1 Reply Last reply
      0
      • _ _Superman_

        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 returns ERROR_ALREADY_EXISTS the EXE can quit itself using PostQuitMessage[^].

        «_Superman_» I love work. It gives me something to do between weekends.

        K Offline
        K Offline
        kb boxer
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups