Checking Instance of Application

Hi, now I'm working on some school projects..

I want to make an application that before it start running, it will check if there is another instance have already running before. If there is a previous instance found, it will show some message and then close itself. If not it will show it's form and run normally...

thanks before..

Best regards,

Satria Ady Pradana


  • Create a uniquely named mutex using [link=]CreateMutex[/link]. If you get the ERROR_ALREADY_EXISTS error, then you know there is another instance of the application running.
  • Thank you for your reply, but actually i've done it in another way

    I open main source
    > project -> View Source

    Searching for WinMain function which is like this

    Normally if there is no another instance before, the 2nd argument value will be initialized with NULL value, then i will check the 2nd argument which is hPrevInstance. If it's not NULL value, then there must be another instance before. So i give some change to 2nd argument like this

    Then in 2nd argument, i change it become like this
    HINSTANCE hPrevInstance

    Then the codes become like this

    WINAPI WinMain(HINSTANCE, HINSTANCE hPrevInstance, LPSTR, int) {

    if(hPrevInstance != NULL) Application->Terminate();

    // and bla bla bla


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!