????? C++ ??? ?? ??????? ?? ??? 32-??? ??????????? ?? ????? ???? ?? ??? ???? ????

???? ?????? ???? ??????
???? ID: 243953 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
???:Microsoft Visual C++ 2005, Microsoft Visual C++ .NET 2003, ?? Microsoft Visual C++ .NET 2002 Microsoft .NET Framework ?????? ??? ?? ??? ?? ???????? ???? ?? ????????? ??? Microsoft Windows ??? ???? ?? ??? ??????? ?? ???? ??? ?? ?? ??????? ???? ????????? ????? C++ ??? ?? ??? ???? ???? ???
??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ???? ????? ???? ?? ?? ???? ?? ??????? ?? ??? ??? ????????? ?? ????? ???? ?? ???? ?? ???? ??? ???????? ???? ???? ???? ????? ?? ???? ?? ??????? ?? ?????? ???? ??? ?????, ?? ?????? ?? ?? ????? C++ ??? ?????? ???? ?? ??? ??? ????????? ?? ????? ???? ?? ??? ?????? ????? ???? ?? ????? ????? ????? ????? ?????????, WinCE ?????????, ????? ????? ?????? ???????????, ???? ???? ???????? ???? ??????? ???????????, ?? ???? ??????????? ???

???? ???????

?? ???? ??? ???????? ???? ???? ???? ?? ?? WinMain ???? ?? ??? MSDN ??? ????? ???? ??? ?? ??? ?? ????? ???? ??CreateMutex?????? ??? mutex ??????????? ?? ??? ??? ???? ?? ???? ?? ????? ?? ??? ??? ???? ?? ??????? ?? ??? ??? ????? ?????? ?? ???????? ????????? ?? ??? ???? ??? duplicating, ?? ????? ?? ???? ????? ?? ??? ?? ?? ???????? ????????? ?? ???: ????? ?? ???? ??? ?? C++ ???? ???? ????

?? ??????????? ?? ????? ????, ????? ????? ?? ???? ????:
  1. ??? ?? ??? ????? ??? ?? ?? ?? ????? ????? LimitSingleInstance.h, ?? ???? ??? ??? ???? ????????? ??? ???????
  2. LimitSingleInstance.h ????? ??? ????? ??? ?? ????????? ?????, ?? ???? ??? ????? ?? ??????:
    #ifndef LimitSingleInstance_H
    #define LimitSingleInstance_H
    
    #include <windows.h> 
    
    //This code is from Q243953 in case you lose the article and wonder
    //where this code came from.
    class CLimitSingleInstance
    {
    protected:
      DWORD  m_dwLastError;
      HANDLE m_hMutex;
    
    public:
      CLimitSingleInstance(TCHAR *strMutexName)
      {
        //Make sure that you use a name that is unique for this application otherwise
        //two apps may think they are the same if they are using same name for
        //3rd parm to CreateMutex
        m_hMutex = CreateMutex(NULL, FALSE, strMutexName); //do early
        m_dwLastError = GetLastError(); //save for use later...
      }
       
      ~CLimitSingleInstance() 
      {
        if (m_hMutex)  //Do not forget to close handles.
        {
           CloseHandle(m_hMutex); //Do as late as possible.
           m_hMutex = NULL; //Good habit to be in.
        }
      }
    
      BOOL IsAnotherInstanceRunning() 
      {
        return (ERROR_ALREADY_EXISTS == m_dwLastError);
      }
    };
    #endif
    					
    ???:????? C++ 2005, ??? ?? ??????? ???? ?????? ?????? ??????? ?????? ?? ?????? ???? (/ clr:oldSyntax) ??????????? ????? ??? ????? ?? ?????? ???? ?? ???? ????? ?? ??? ??????? ???? ?????? ?????? ??????? ??????, ?? ????? ?? ???? ????:
    1. ????? ????,??????????? ????-????? ????, ?? ???? ???ProjectName???.

      ???:ProjectName????????? ?? ??? ?? ??? ?? ??????????? ???
    2. ??????? ??????????????? ????? ????-????? ????, ?? ???? ??????????.
    3. ???? ??? ???, ????? ???? ?? ??? ???? ?? ?????????? ???? ?????? ??????, ?????? ???????? (/ clr:oldSyntax)???????????? ???? ?????? ??????????????? ?????????
    4. ????? ????,???? ?????? ????-????? ????, ?? ???? ???OK.
    ??????? ???? ?????? ?????? ??????? ???????? ?? ???? ??? ???? ??????? ?? ??? ????? Microsoft ?????? ??????? (MSDN) ??? ???? ?? ????:
    HTTP://msdn2.Microsoft.com/en-us/library/k8d11d4s.aspx
  3. # ???? ????????? ?? ????????? ????? ?? ????? ?? LimitSingleInstance.h ????? ????? ??? ??? ?? ?? MFC ????????? ??? ????? ???? ?? ???? ??, ?? ????? ?? ????InitInstance()????????? ?? ??? ?????? ????? ??? ?? Win32 SDK ??? ?????????, ?? ???? ??WinMain()?????? ????? ??? ????? ??? ????????? ??? ?? ?? ?? ????main()?????? ????? ???
    #include "LimitSingleInstance.H"
    					
  4. ?? ??????? ?? ??????? ?????CLimitSingleInstance???? ????????? ????? ?????? ?????? ??? ??? ?? ?? MFC ????????? ??? ????? ???? ?? ??? ??, ???? ?? ???? ???? ???????? ?????InitInstance()?????? ?? ??? ???? ???..
  5. ??? ????? ??? ?? ??????? constructor ?? ???CLimitSingleInstance?????? ?? ???? ?? ??????? ?? ???? ?? ?? ?? ?? ????? ??? ????? ??? ????? ?? ???? ????? ???? ?? ???? ?? ?? ???? ???? ????????? ????? ???? ????? ?? ????????? ???? ?? ??? ??? GUIDGEN ????? ?? ????? ???? ?? ??? no ?? ?? ???? ?? ???? ????? ??? ??????? ???? ?? ??? ?? ???? ????? ??? ????? ?? ????? ??, ?? ??? ????? ???????????????? ????,?????, ?? ??? ???? ????GUIDGEN. ??? ??? ???? ?? ??? ???? ??? ???? ?????, ????? MSDN ?? ?? ????? ?? ??? ??? ???? ??? ??? ??????:GUIDGEN??? ??? ?????? ?? ??? MSDN ???????????? ????????? ???? ?? ?? ?? ????? ????????????? ?? ???????????? GUIDGEN ??? ??????
    #include "LimitSingleInstance.H"
    
    // The one and only CLimitSingleInstance object.
    // Change what is passed to constructor. GUIDGEN Tool may be of help.
    CLimitSingleInstance g_SingleInstanceObj(TEXT("Global\\{719967F0-DCC6-49b5-9C61-DE91175C3187}"));
    					
  6. ???? ????????? ????? ??????, ??? ???IsAnotherInstanceRunning()?? ??????? ??????? ?? ????CLimitSingleInstance???? ?? ????? ??? ??? ????? ??? ?????? TRUE ???? ??, ?? ????????? ????? ?????? ?? ???? ?????? ??????, ???????? ?? ??????? ?? ??? ??? ???? ?????

    ??? MFC ????????? ??? ???? ????? ?? ???? ??? ?? ???? ?? ???? ??:
    #include "LimitSingleInstance.H"
    
    // The one and only CLimitSingleInstance object.
    CLimitSingleInstance g_SingleInstanceObj(TEXT("Global\\{05CA3573-B449-4e0b-83F5-7FD612E378E9}"));
    
    BOOL CSingleInstDlg5App::InitInstance()
    {
        if (g_SingleInstanceObj.IsAnotherInstanceRunning())
           return FALSE; 
    
    //Rest of code.
    }
    						
    ????? ??? ????????? ??? ???? ????? ?? ???? ??? ?? ???? ?? ???? ??:
    #include "LimitSingleInstance.H"
    
    // The one and only CLimitSingleInstance object.
    CLimitSingleInstance g_SingleInstanceObj(TEXT("Global\\{9DA0BEED-7248-450a-B27C-C0409BDC377D}"));
    
    int main(int argc, char* argv[])
    {
        if (g_SingleInstanceObj.IsAnotherInstanceRunning())
           return 0;
    //Rest of code.
    }
    						
    ??? ?? Win32 SDK ?????????, ?? ?? ???? ??? ???? ???? ???? ?????:
    #include "LimitSingleInstance.H"
    
    // The one and only CLimitSingleInstance object.
    CLimitSingleInstance g_SingleInstanceObj(TEXT("Global\\{2194ABA1-BFFA-4e6b-8C26-D191BB16F9E6}"));
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int cmdShow)
    {
        if (g_SingleInstanceObj.IsAnotherInstanceRunning())
           return FALSE; 
    //Rest of code.
    }
    						
????? ?????, ?? ??? ????????? ???? ?? ?? ??? ??? ?????? ???? ?? ??? ?? ?? ???? ???????? ?????? ?????

???:??????? ???? ?? ??????? ?? ??? ??, ?? ???? ??? Global\ ??????? ???? ???? ?? ????? ?? ??????? ?? ?? ?????? ?? ?????
   CLimitSingleInstance g_SingleInstanceObj(TEXT("{719967F0-DCC6-49b5-9C61-DE91175C3187}"));
					
?? ?????? "Global\" ?????? ???? ?? ?? ?? ???????? ?? ????????? ?? ???? ?? ??????? ?? ???? ???? ?? ?? ??????? ???? ??? ??? ?? ?? ?????

??????

???? ??????? ?? ???, Microsoft ?????? ??? ??? ???? ????? ?? ??? ????? ???? ?????? ????? ????::
23810032-??? MFC SDI ????????? WinCE ?? ???? ?? ??????? ?? ????? ???? ?? ??? ???? ????

???

???? ID: 243953 - ????? ???????: 02 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 4.2 Enterprise Edition
??????: 
kbinfo kbhowto kbuidesign kbmt KB243953 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:243953

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com