none
There is already an instance of this app running? RRS feed

  • Question

  • When I try to copy a skeletalViewer c++ example, and try to run two skeletalViewers on the same desktop with two independent Kinect, I got this error : "There is already an instance of this app running" for the secondarily running application.

    How can I modify the sample code so each skeletalViewer will only call one instance. It seems that just changing the

    HRESULT hr = NuiCreateSensorByIndex(0, &m_pNuiSensor);

    to

    HRESULT hr = NuiCreateSensorByIndex(1, &m_pNuiSensor);

    within HRESULT CSkeletalViewerApp::Nui_Init( ){} function is not enough...


    Lining YAO

    Wednesday, March 7, 2012 6:53 PM

Answers

  • This is the code (in SkeletalViewer.cpp) that prevents more than one instance from running:

        // unique mutex, if it already exists there is already an instance of this app running
        // in that case we want to show the user an error dialog
        HANDLE hMutex = CreateMutex( NULL, FALSE, INSTANCE_MUTEX_NAME );
        if ( (hMutex != NULL) && (GetLastError() == ERROR_ALREADY_EXISTS) ) 
        {
            //load the app title
            TCHAR szAppTitle[256] = { 0 };
            LoadString( hInstance, IDS_APPTITLE, szAppTitle, _countof(szAppTitle) );
     
            //load the error string
            TCHAR szRes[512] = { 0 };
            LoadString( hInstance, IDS_ERROR_APP_INSTANCE, szRes, _countof(szRes) );
     
            MessageBox( NULL, szRes, szAppTitle, MB_OK | MB_ICONHAND );
     
            CloseHandle(hMutex);
            return -1;
        }
    Thursday, March 8, 2012 12:51 AM