SHARE
TWEET

Untitled

a guest Nov 18th, 2019 78 in 159 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. HANDLE hMutex;
  2.  
  3. //-------------------------------------------------------------------------—
  4.  
  5. __fastcall TForm1::TForm1(TComponent* Owner)
  6. : TForm(Owner)
  7. {
  8. hMutex = OpenMutex(MUTEX_ALL_ACCESS,0,(ExtractFilePath(Application->ExeName)+Application->ExeName).w_str());
  9. if(hMutex==NULL)
  10. //ИЛИ может быть так: if(GetLastError()!=ERROR_ALREADY_EXISTS)
  11. {
  12. hMutex = CreateMutex(0,true,(ExtractFilePath(Application->ExeName)+Application->ExeName).w_str());
  13. }
  14. else
  15. {
  16. ShowMessage("ОШИБКА!!! Экземпляр приложения уже запущен");
  17. Application->Terminate();
  18. }
  19. }
  20. //-------------------------------------------------------------------------—
  21.  
  22. void __fastcall TForm1::FormDestroy(TObject *Sender)
  23. {
  24. ReleaseMutex(hMutex);
  25. CloseHandle(hMutex);
  26. }
  27. //---------------------------------------------------------------------------
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top