summaryrefslogtreecommitdiff
path: root/plugins/Actman30/iac_global.pas
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Actman30/iac_global.pas')
-rw-r--r--plugins/Actman30/iac_global.pas101
1 files changed, 72 insertions, 29 deletions
diff --git a/plugins/Actman30/iac_global.pas b/plugins/Actman30/iac_global.pas
index 1d7957a3bc..cba955d762 100644
--- a/plugins/Actman30/iac_global.pas
+++ b/plugins/Actman30/iac_global.pas
@@ -89,8 +89,8 @@ procedure InsertString(wnd:HWND;num:dword;str:PAnsiChar);
function GetLink(hash:dword):pActModule;
function GetLinkByName(name:pAnsiChar):pActModule;
-function ImportContact (node:HXML ):THANDLE;
-function ImportContactINI(node:pointer):THANDLE;
+function ImportContact (node:HXML ):HCONTACT;
+function ImportContactINI(node:pointer):HCONTACT;
implementation
@@ -301,7 +301,7 @@ const
ioCUID = 'cuid';
ioCUIDType = 'cuidtype';
-function ImportContact(node:HXML):THANDLE;
+function ImportContact(node:HXML):HCONTACT;
var
proto:pAnsiChar;
tmpbuf:array [0..63] of AnsiChar;
@@ -352,7 +352,7 @@ begin
end;
end;
-function ImportContactINI(node:pointer):THANDLE;
+function ImportContactINI(node:pointer):HCONTACT;
{
var
proto:pAnsiChar;
@@ -441,48 +441,84 @@ type
const
actDLLCache: tDLLCache = nil;
-function GetDllHandle(dllname:pAnsiChar;mode:dword=0):THANDLE;
+function GetDllHandle(adllname:pAnsiChar;mode:dword=0):THANDLE;
var
- i:integer;
+ i,zero:integer;
begin
- result:=LoadLibraryA(dllname);
-exit;
+ // 1 - search that name in cache
i:=0;
+ zero:=-1;
while i<=HIGH(actDLLCache) do
begin
- if StrCmp(actDLLCache[i].DllName,dllname)=0 then
+ with actDLLCache[i] do
begin
- result:=actDLLCache[i].DllHandle;
- // check mode
- exit;
+ // remember first empty slot
+ if DllHandle=0 then
+ begin
+ if zero<0 then
+ zero:=i;
+ end
+ else if StrCmp(DllName,adllname)=0 then
+ begin
+ result:=DllHandle;
+ inc(count);
+ if mode=3 then // per-session
+ flags:=3;
+ exit;
+ end;
end;
inc(i);
end;
- result:=LoadLibraryA(dllname);
- // check mode
- SetLength(actDLLCache,i);
- StrDup(actDLLCache[i].DllName,dllname);
- actDLLCache[i].DllHandle:=result;
-// actDLLCache.flags:=;
+ // 2 - not found, load library
+ result:=LoadLibraryA(adllname);
+ // 3 - add to cache if not per-action
+ if mode<>0 then
+ begin
+ if zero>=0 then
+ i:=zero
+ else
+ begin
+ SetLength(actDLLCache,i);
+ dec(i);
+ end;
+
+ with actDLLCache[i] do
+ begin
+ StrDup(DllName,adllname);
+ DllHandle:=result;
+ count :=0;
+ flags :=mode;
+ end;
+ end;
end;
procedure CloseDllHandle(handle:THANDLE);
var
i:integer;
begin
- FreeLibrary(handle);
-exit;
- i:=0;
- while i<=HIGH(actDLLCache) do
+ i:=HIGH(actDLLCache);
+ while i>=0 do
begin
- if actDLLCache[i].DllHandle=handle then
+ with actDLLCache[i] do
begin
- // check mode
- FreeLibrary(actDLLCache[i].DllHandle);
- exit;
+ if DllHandle=handle then
+ begin
+ dec(count);
+ if count=0 then
+ begin
+ if flags=2 then // per-macro+not needed -> free
+ begin
+ FreeLibrary(DllHandle);
+ DllHandle:=0;
+ mFreeMem(DllName);
+ end;
+ end;
+ exit;
+ end;
end;
- inc(i);
+ dec(i);
end;
+ // if not found in cache
FreeLibrary(handle);
end;
@@ -490,10 +526,17 @@ procedure FreeDllHandleCache;
var
i:integer;
begin
- i:=0;
- while i<=HIGH(actDLLCache) do
+ i:=HIGH(actDLLCache);
+ while i>=0 do
begin
+ if actDLLCache[i].DllHandle<>0 then
+ begin
+ FreeLibrary(actDLLCache[i].DllHandle);
+ mFreeMem(actDLLCache[i].DllName);
+ end;
+ dec(i);
end;
+ SetLength(actDLLCache,0);
end;
end.