CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    NT - checking if another instance of a program is running

    Hi!

    I Use this code to check if another instance of a program is running. It works in win 95, but not in Windows NT.
    If the program crasch in NT it is impossible to start it again, because the application thinks another instance is still running.

    Is there any other way to solve this problem in windows NT?

    /Beginner

    <----------- CODE BEGIN --------------->

    // Checking if another instance of a program is running
    HANDLE hMapping;
    int iRes;

    hMapping = CreateFileMapping( (HANDLE) 0xffffffff,
    NULL, PAGE_READONLY,
    0, 32, "MyTestMap" );

    loggfil.logga("WinMain - CreateFileMapping");

    if( hMapping )
    { if( GetLastError() == ERROR_ALREADY_EXISTS )
    {
    loggfil.logga("WinMain - Another instance of ivclip is already running. Exiting.");
    ExitProcess(1);
    }
    }
    else
    { ExitProcess(1); }



  2. #2
    Join Date
    Jun 1999
    Posts
    16

    Re: NT - checking if another instance of a program is running

    you can try something like this in InitInstance() :

    m_mutex = CreateMutex( NULL, TRUE, _T("MyApp"));
    if( GetLastError() == ERROR_ALREADY_EXISTS) {
    ::MessageBox( NULL, _T("An instance is already running."),
    _T("ERROR!"), MB_OK | MB_ICONEXCLAMATION );
    return TRUE;
    }



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured