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. C / C++ / MFC
  4. Singleton using mutex for windows application (exe)

Singleton using mutex for windows application (exe)

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
6 Posts 5 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.
  • H Offline
    H Offline
    hariakuthota
    wrote on last edited by
    #1

    Hi, in my application I have to support single instance functionality I tried with FindWindow and sendmessage but it failed in some times so I want to try with mutex,can anybody suggest me how to support single instance with mutex? Thanks in advance....

    R K A 3 Replies Last reply
    0
    • H hariakuthota

      Hi, in my application I have to support single instance functionality I tried with FindWindow and sendmessage but it failed in some times so I want to try with mutex,can anybody suggest me how to support single instance with mutex? Thanks in advance....

      R Offline
      R Offline
      ramana g
      wrote on last edited by
      #2

      you can add some code like this... in your application initinstance HANDLE hMutex = CreateMutex( NULL, TRUE, "MyMutex" ); if( GetLastError() == ERROR_ALREADY_EXISTS ) {//application is already running. dont proceed further CloseHandle( hMutex ); return FALSE; }

      1 Reply Last reply
      0
      • H hariakuthota

        Hi, in my application I have to support single instance functionality I tried with FindWindow and sendmessage but it failed in some times so I want to try with mutex,can anybody suggest me how to support single instance with mutex? Thanks in advance....

        K Offline
        K Offline
        KarstenK
        wrote on last edited by
        #3

        since w2k sp4 it is better to use global mutexes: HANDLE hMutex = CreateMutex( NULL, TRUE, "Global\\MyMutex" ); to aovid conflicts in multiple sessions.

        Greetings from Germany

        S 1 Reply Last reply
        0
        • K KarstenK

          since w2k sp4 it is better to use global mutexes: HANDLE hMutex = CreateMutex( NULL, TRUE, "Global\\MyMutex" ); to aovid conflicts in multiple sessions.

          Greetings from Germany

          S Offline
          S Offline
          santhoshv84
          wrote on last edited by
          #4

          Hi, Try this Link[^]

          The price of anything is the amount of life you exchange for it. Thanks and Regards. SANTHOSH V

          K 1 Reply Last reply
          0
          • S santhoshv84

            Hi, Try this Link[^]

            The price of anything is the amount of life you exchange for it. Thanks and Regards. SANTHOSH V

            K Offline
            K Offline
            KarstenK
            wrote on last edited by
            #5

            dont mix C# and C !!! I mean this stuff: http://msdn.microsoft.com/en-us/library/ms682411(VS.85).aspx[^]

            Greetings from Germany

            1 Reply Last reply
            0
            • H hariakuthota

              Hi, in my application I have to support single instance functionality I tried with FindWindow and sendmessage but it failed in some times so I want to try with mutex,can anybody suggest me how to support single instance with mutex? Thanks in advance....

              A Offline
              A Offline
              Ali Tavakol
              wrote on last edited by
              #6

              See the link below. There is a video and source code from microsoft, to show how to restrict to a single instance. also switch to active instance when running a new instance. http://msdn.microsoft.com/en-us/visualc/bb924354.aspx[^]

              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