forked from gligli/SuperCopier2
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSCAPIClient.pas
More file actions
131 lines (106 loc) · 3.55 KB
/
Copy pathSCAPIClient.pas
File metadata and controls
131 lines (106 loc) · 3.55 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
unit SCAPIClient;
{$message warn 'SCAPIClient n''est plus utilisé et n''est plus à jour, voir l''implémenation C++'}
interface
uses Windows,Classes,SysUtils,
SCWin32,SCAPICommon;
type
EAPIClientError=class(Exception);
TAPIClient=class
private
FMutex:THandle;
FFileMapping:THandle;
FClientEvent:THandle;
FAPIEvent:THandle;
FFileMappingStream:TFileMappingStream;
public
constructor Create;
destructor Destroy;override;
procedure Lock;
procedure UnLock;
procedure SendAndWaitResult;
property FileMappingStream:TFileMappingStream read FFileMappingStream;
end;
var APIClient:TAPIClient=nil;
{
function TestI2S(Value:Integer):WideString;
function TestS2I(Value:WideString):Integer;
}
implementation
{ TAPIClient }
constructor TAPIClient.Create;
begin
inherited;
FMutex:=SCWin32.OpenMutex(MUTEX_ALL_ACCESS,False,PWideChar(SessionUniqueAPIIdentifier(SC2_API_MUTEX_ID)));
if FMutex=0 then
raise EAPIClientError.Create('Couldn''t open mutex');
FFileMapping:=SCWin32.OpenFileMapping(FILE_MAP_ALL_ACCESS,False,PWideChar(SessionUniqueAPIIdentifier(SC2_API_FILEMAPPING_ID)));
if FFileMapping=0 then
raise EAPIClientError.Create('Couldn''t open file mapping');
FClientEvent:=SCWin32.OpenEvent(EVENT_ALL_ACCESS,False,PWideChar(SessionUniqueAPIIdentifier(SC2_API_CLIENTEVENT_ID)));
if FClientEvent=0 then
raise EAPIClientError.Create('Couldn''t open client event');
FAPIEvent:=SCWin32.OpenEvent(EVENT_ALL_ACCESS,False,PWideChar(SessionUniqueAPIIdentifier(SC2_API_APIEVENT_ID)));
if FAPIEvent=0 then
raise EAPIClientError.Create('Couldn''t open API event');
FFileMappingStream:=TFileMappingStream.Create(FFileMapping,SC2_API_FILEMAPPING_SIZE);
end;
destructor TAPIClient.Destroy;
begin
CloseHandle(FAPIEvent);
CloseHandle(FClientEvent);
FFileMappingStream.Free;
CloseHandle(FFileMapping);
CloseHandle(FMutex);
inherited;
end;
procedure TAPIClient.Lock;
begin
WaitForSingleObject(FMutex,INFINITE);
// au passsage ...
FileMappingStream.Seek(0,soFromBeginning);
end;
procedure TAPIClient.SendAndWaitResult;
begin
SetEvent(FClientEvent);
WaitForSingleObject(FAPIEvent,INFINITE);
// au passsage ...
FFileMappingStream.Seek(0,soFromBeginning);
end;
procedure TAPIClient.UnLock;
begin
ReleaseMutex(FMutex);
end;
//******************************************************************************
//******************************************************************************
//******************************************************************************
// Fonctions de l'API
//******************************************************************************
//******************************************************************************
//******************************************************************************
{
function TestI2S(Value:Integer):WideString;
begin
APIClient.Lock;
try
APIClient.FileMappingStream.WriteInteger(Integer(afTestI2S));
APIClient.FileMappingStream.WriteInteger(Value);
APIClient.SendAndWaitResult;
Result:=APIClient.FileMappingStream.ReadWideString;
finally
APIClient.UnLock;
end;
end;
function TestS2I(Value:WideString):Integer;
begin
APIClient.Lock;
try
APIClient.FileMappingStream.WriteInteger(Integer(afTestS2I));
APIClient.FileMappingStream.WriteWideString(Value);
APIClient.SendAndWaitResult;
Result:=APIClient.FileMappingStream.ReadInteger;
finally
APIClient.UnLock;
end;
end;
}
end.