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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with mutex

Problem with mutex

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 Posts 3 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.
  • A Offline
    A Offline
    Artem Moroz
    wrote on last edited by
    #1

    I have a problem with named mutex. In my 1st process I am creating mutex CreateMutex(NULL,TRUE,"Process_Running"); // mutex will be automatically deleted when process ends. if(GetLastError() == ERROR_ALREADY_EXISTS) { AfxMessageBox(IDS_ALREADYRUN); } Then, in 2nd process I am try to determine, whether 1st process is running: HANDLE hMutex = OpenMutex(0,FALSE,"Process_Running"); if (hMutex != NULL) { CloseHandle(hMutex); // Do something... } But in this code hMutex is always NULL ! Even if 1st process is running! What am I doing wrong ?

    J M 2 Replies Last reply
    0
    • A Artem Moroz

      I have a problem with named mutex. In my 1st process I am creating mutex CreateMutex(NULL,TRUE,"Process_Running"); // mutex will be automatically deleted when process ends. if(GetLastError() == ERROR_ALREADY_EXISTS) { AfxMessageBox(IDS_ALREADYRUN); } Then, in 2nd process I am try to determine, whether 1st process is running: HANDLE hMutex = OpenMutex(0,FALSE,"Process_Running"); if (hMutex != NULL) { CloseHandle(hMutex); // Do something... } But in this code hMutex is always NULL ! Even if 1st process is running! What am I doing wrong ?

      J Offline
      J Offline
      John M Drescher
      wrote on last edited by
      #2

      It looks like you want to limit your application to single instance. Here is some code for that: http://www.codeproject.com/cpp/csingleinst.asp[^] http://www.codeproject.com/useritems/single_instance_checker.asp[^] John

      1 Reply Last reply
      0
      • A Artem Moroz

        I have a problem with named mutex. In my 1st process I am creating mutex CreateMutex(NULL,TRUE,"Process_Running"); // mutex will be automatically deleted when process ends. if(GetLastError() == ERROR_ALREADY_EXISTS) { AfxMessageBox(IDS_ALREADYRUN); } Then, in 2nd process I am try to determine, whether 1st process is running: HANDLE hMutex = OpenMutex(0,FALSE,"Process_Running"); if (hMutex != NULL) { CloseHandle(hMutex); // Do something... } But in this code hMutex is always NULL ! Even if 1st process is running! What am I doing wrong ?

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        The first param to OpenMutex() should be MUTEX_ALL_ACCESS. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER

        A 1 Reply Last reply
        0
        • M Michael Dunn

          The first param to OpenMutex() should be MUTEX_ALL_ACCESS. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER

          A Offline
          A Offline
          Artem Moroz
          wrote on last edited by
          #4

          It works! Thank you for help ! ;)

          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