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. How to Run only One Instance of my Application at a time

How to Run only One Instance of my Application at a time

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
3 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.
  • Z Offline
    Z Offline
    Zeeshan Bilal
    wrote on last edited by
    #1

    I want to run only one instance of my application at a time at my User's PC . if he try to run another instance by clicking on EXE ,, he will recvie an error message. i have a little idea , i thin it is by some static function and static data member to have count of instances. ... and there may b a rule of Constructor .. but i cant do it ..where to write and how any idea or Code sample thanx

    PJ ArendsP V 2 Replies Last reply
    0
    • Z Zeeshan Bilal

      I want to run only one instance of my application at a time at my User's PC . if he try to run another instance by clicking on EXE ,, he will recvie an error message. i have a little idea , i thin it is by some static function and static data member to have count of instances. ... and there may b a rule of Constructor .. but i cant do it ..where to write and how any idea or Code sample thanx

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      http://www.codeproject.com/cpp/avoidmultinstance.asp[^]


      [

      ](http://www.canucks.com)"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

      Within you lies the power for good; Use it!

      1 Reply Last reply
      0
      • Z Zeeshan Bilal

        I want to run only one instance of my application at a time at my User's PC . if he try to run another instance by clicking on EXE ,, he will recvie an error message. i have a little idea , i thin it is by some static function and static data member to have count of instances. ... and there may b a rule of Constructor .. but i cant do it ..where to write and how any idea or Code sample thanx

        V Offline
        V Offline
        vikram attiganal
        wrote on last edited by
        #3

        //---------------------------------------------------------------------------------------------------// //check if the application is already running... bool bAlreadyRunning; HANDLE hMutexOneInstance = CreateMutex( NULL, TRUE, "Pointer to a null-terminated string specifying the name of the mutex object."); bAlreadyRunning = ( GetLastError() == ERROR_ALREADY_EXISTS ); if ( hMutexOneInstance ) { ReleaseMutex( hMutexOneInstance ); } if ( bAlreadyRunning ) { //AfxMessageBox("Application is already running"); return FALSE; } //---------------------------------------------------------------------------------------------------// Include this code in the InitInstance of your app. This will do the trick for you.

        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