Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library project1;
- {$mode objfpc}{$H+}
- {$macro on}
- uses
- SysUtils,
- Classes,
- Math;
- type
- TIntArray = Array of Int32;
- var
- OldMemoryManager: TMemoryManager;
- memisset: Boolean = False;
- function TIAThing(Arr:TIntArray): TIntArray; cdecl;
- begin
- Result := Copy(Arr, 0,Length(Arr));
- end;
- {=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=]
- Export our functions, name, information etc...
- All that is needed for scar to see this as a DLL.
- [=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}
- function GetPluginABIVersion: Integer; cdecl; export;
- begin
- Result := 2;
- end;
- procedure SetPluginMemManager(MemMgr : TMemoryManager); cdecl; export;
- begin
- if memisset then
- exit;
- GetMemoryManager(OldMemoryManager);
- SetMemoryManager(MemMgr);
- memisset := true;
- end;
- procedure OnDetach; cdecl; export;
- begin
- SetMemoryManager(OldMemoryManager);
- end;
- //Count of functions that will be exported...
- function GetFunctionCount(): Integer; cdecl; export;
- begin Result := 1; end;
- //Information about our functions...
- function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; cdecl; export;
- begin
- case x of
- 0:begin
- ProcAddr := @TIAThing;
- StrPCopy(ProcDef, 'function TIAThing(Arr:TIntArray): TIntArray; cdecl;');
- end;
- else
- x := -1;
- end;
- Result := x;
- end;
- exports GetPluginABIVersion;
- exports SetPluginMemManager;
- exports GetFunctionCount;
- exports GetFunctionInfo;
- exports OnDetach;
- begin
- end.
- //=================================================================================================\\
- program new;
- type TIntArray = TIntegerArray;
- {$loadlib project1.dll}
- var
- i:Int32;
- v,a:TIntArray;
- begin
- SetLength(v, 10000000);
- for i:=0 to 5 do
- begin
- a := TIAThing(v);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement