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. About CMutex : Plz Help

About CMutex : Plz Help

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
8 Posts 6 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.
  • P Offline
    P Offline
    parims
    wrote on last edited by
    #1

    :rolleyes:I developed one scheduler application. When I run this applcation (scheduler.exe)it is running. Next If I start another (scheduler.exe) is running. How to stop another process .,when One process is in running. Plz give reply urgently. Praveen Chowdam Kumar

    K T S E 4 Replies Last reply
    0
    • P parims

      :rolleyes:I developed one scheduler application. When I run this applcation (scheduler.exe)it is running. Next If I start another (scheduler.exe) is running. How to stop another process .,when One process is in running. Plz give reply urgently. Praveen Chowdam Kumar

      K Offline
      K Offline
      karmendra_js
      wrote on last edited by
      #2

      Yesterday I solved this problem. Try the following link. http://www.codeproject.com/cpp/avoidmultinstance.asp OR Try following solution. Insert the following code in YourApp::InitInstance(). bool AlreadyRunning; HANDLE hMutexOneInstance = ::CreateMutex( NULL, TRUE, UNIQUE_GUID); AlreadyRunning = (GetLastError() == ERROR_ALREADY_EXISTS); if (hMutexOneInstance != NULL) { ::ReleaseMutex(hMutexOneInstance); } if ( AlreadyRunning ) { /* kill this */ AfxMessageBox("Application instance already running"); HWND hOther = g_hWnd; if (hOther != NULL) { /* pop up */ ::SetForegroundWindow(hOther); if (IsIconic(hOther)) { /* restore */ ::ShowWindow(hOther, SW_RESTORE); } /* restore */ } /* pop up */ return FALSE; // terminates the creation } /* kill this */ // ... continue with InitInstance UNIQUE_GUID is defined as #define UNIQUE_GUID _T("YourAppName{1C7496E6-5949-4907-9F3E-CE26ED9EEB78}") I generated this string using GUIDGEN.EXE (Visual Studio tool). String here is new string you can use it.

      B 1 Reply Last reply
      0
      • P parims

        :rolleyes:I developed one scheduler application. When I run this applcation (scheduler.exe)it is running. Next If I start another (scheduler.exe) is running. How to stop another process .,when One process is in running. Plz give reply urgently. Praveen Chowdam Kumar

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        parims wrote: How to stop another process .,when One process is in running. In Conitnuation With Poster Above my post.... you can depend upon this wrapper class too... http://www.codeproject.com/cpp/csingleinst.asp[^]

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        cheers, Alok Gupta VC Forum Q&A :- I/ IV

        1 Reply Last reply
        0
        • P parims

          :rolleyes:I developed one scheduler application. When I run this applcation (scheduler.exe)it is running. Next If I start another (scheduler.exe) is running. How to stop another process .,when One process is in running. Plz give reply urgently. Praveen Chowdam Kumar

          S Offline
          S Offline
          Sonani Prakash
          wrote on last edited by
          #4

          Hi You Can create mutex in Scheduler.exe in CWinApp class of MFC application with some name suppose XXXX. and at the same time you check whether it is giving successful or fail fail response. if it is successful then scheduler.exe is running first time and if it is giving fail that means one instance is already running... sonani prakash

          1 Reply Last reply
          0
          • P parims

            :rolleyes:I developed one scheduler application. When I run this applcation (scheduler.exe)it is running. Next If I start another (scheduler.exe) is running. How to stop another process .,when One process is in running. Plz give reply urgently. Praveen Chowdam Kumar

            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #5

            if limiting your application to one instance is your need, you can try this .. put this inside OnInitInstance() if(FindWindow(NULL,"YourAppName")==NULL) AfxMessageBox("1 and 1ly"); else PostQuitMessage(0); Regards, V

            B T 2 Replies Last reply
            0
            • K karmendra_js

              Yesterday I solved this problem. Try the following link. http://www.codeproject.com/cpp/avoidmultinstance.asp OR Try following solution. Insert the following code in YourApp::InitInstance(). bool AlreadyRunning; HANDLE hMutexOneInstance = ::CreateMutex( NULL, TRUE, UNIQUE_GUID); AlreadyRunning = (GetLastError() == ERROR_ALREADY_EXISTS); if (hMutexOneInstance != NULL) { ::ReleaseMutex(hMutexOneInstance); } if ( AlreadyRunning ) { /* kill this */ AfxMessageBox("Application instance already running"); HWND hOther = g_hWnd; if (hOther != NULL) { /* pop up */ ::SetForegroundWindow(hOther); if (IsIconic(hOther)) { /* restore */ ::ShowWindow(hOther, SW_RESTORE); } /* restore */ } /* pop up */ return FALSE; // terminates the creation } /* kill this */ // ... continue with InitInstance UNIQUE_GUID is defined as #define UNIQUE_GUID _T("YourAppName{1C7496E6-5949-4907-9F3E-CE26ED9EEB78}") I generated this string using GUIDGEN.EXE (Visual Studio tool). String here is new string you can use it.

              B Offline
              B Offline
              Blake Miller
              wrote on last edited by
              #6

              This is FAR TOO OFTEN overlooked aspect of naming synchronization objects. If this is run from a terminal services console or as a service, that is the only instance that can work on the entire system - the mutext will be seen across all sessions. If this is started first from a terminal services session, then other sessions could also start, since the mutex will have local scope. If you REALLY REALLY only want one instance on the enire computer, then you need to put "Global\" in front of your mutex name. If you really want each terminal services session to only run a single instance, then put "Local\" in front of your mutex name. Services and the console terminal services session share the same scope. So, if you want the console session to be able to run at the same time as it runs as a service, then you need a different name when it runs as as service. From MSDN: Terminal Services: The name can have a "Global\" or "Local\" prefix to explicitly create the object in the global or session name space. The remainder of the name can contain any character except the backslash character (\). For more information, see Kernel Object Namespaces. Windows XP Home Edition: Fast user switching is implemented using Terminal Services sessions. The first user to log on uses session 0, the next user to log on uses session 1, and so on. Kernel object names must follow the guidelines outlined for Terminal Services so that applications can support multiple users. Windows 2000: If Terminal Services is not running, the "Global\" and "Local\" prefixes are ignored. The remainder of the name can contain any character except the backslash character. Windows NT: The name can contain any character except the backslash character. Windows Me/98/95: The name can contain any character except the backslash character. The empty string ("") is a valid object name.

              1 Reply Last reply
              0
              • E Eytukan

                if limiting your application to one instance is your need, you can try this .. put this inside OnInitInstance() if(FindWindow(NULL,"YourAppName")==NULL) AfxMessageBox("1 and 1ly"); else PostQuitMessage(0); Regards, V

                B Offline
                B Offline
                Blake Miller
                wrote on last edited by
                #7

                NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER NEVER do this :mad: Your GUI app will hang if another GUI app is hung! The nearly seminal document on avoiding multiple instances is located here: http://www.flounder.com/nomultiples.htm[^]

                1 Reply Last reply
                0
                • E Eytukan

                  if limiting your application to one instance is your need, you can try this .. put this inside OnInitInstance() if(FindWindow(NULL,"YourAppName")==NULL) AfxMessageBox("1 and 1ly"); else PostQuitMessage(0); Regards, V

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #8

                  Vivekuniq wrote: if(FindWindow(NULL,"YourAppName")==NULL) AfxMessageBox("1 and 1ly"); else PostQuitMessage(0); better solution would be to try SingleTon classes or Naughter CSingleInstance class

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  cheers, Alok Gupta VC Forum Q&A :- I/ IV

                  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