-
Notifications
You must be signed in to change notification settings - Fork 15
/
OnlyOneRun.pas
47 lines (38 loc) · 1.46 KB
/
OnlyOneRun.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{ ############################################################################ }
{ # # }
{ # MSpeech v1.5.10 # }
{ # # }
{ # Copyright (c) 2012-2020, Mikhail Grigorev. All rights reserved. # }
{ # # }
{ # License: http://opensource.org/licenses/GPL-3.0 # }
{ # # }
{ # Contact: Mikhail Grigorev (email: [email protected]) # }
{ # # }
{ ############################################################################ }
unit OnlyOneRun;
interface
function Init_Mutex(MId: String): Boolean;
implementation
uses Windows;
var
Mut: THandle;
function Mut_Id(s: String): String;
var
f: integer;
begin
Result := s;
for f := 1 to Length(s) do
if Result[f] = '\' then
Result[f] := '_';
end;
function Init_Mutex(MId: String): Boolean;
begin
Mut := CreateMutex(nil, False, pChar(Mut_Id(Mid)));
Result := not ((Mut = 0) or (GetLastError = ERROR_ALREADY_EXISTS));
end;
initialization
Mut := 0;
finalization
if Mut <> 0 then
CloseHandle(Mut);
end.