Advertisement
WarPie90

Untitled

May 14th, 2014
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.91 KB | None | 0 0
  1. library project1;
  2.  
  3. {$mode objfpc}{$H+}
  4. {$macro on}
  5.  
  6. uses
  7.   SysUtils,
  8.   Classes,
  9.   Math;
  10.  
  11. type
  12.   TIntArray = Array of Int32;
  13.  
  14. var
  15.   OldMemoryManager: TMemoryManager;
  16.   memisset: Boolean = False;
  17.  
  18.  
  19. function TIAThing(Arr:TIntArray): TIntArray; cdecl;
  20. begin
  21.   Result := Copy(Arr, 0,Length(Arr));
  22. end;  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. {=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=]
  29.  Export our functions, name, information etc...
  30.  All that is needed for scar to see this as a DLL.
  31. [=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}
  32. function GetPluginABIVersion: Integer; cdecl; export;
  33. begin
  34.   Result := 2;
  35. end;
  36.  
  37. procedure SetPluginMemManager(MemMgr : TMemoryManager); cdecl; export;
  38. begin
  39.   if memisset then
  40.     exit;
  41.   GetMemoryManager(OldMemoryManager);
  42.   SetMemoryManager(MemMgr);
  43.   memisset := true;
  44. end;
  45.  
  46. procedure OnDetach; cdecl; export;
  47. begin
  48.   SetMemoryManager(OldMemoryManager);
  49. end;
  50.  
  51.  
  52. //Count of functions that will be exported...
  53. function GetFunctionCount(): Integer; cdecl; export;
  54. begin Result := 1; end;
  55.  
  56.  
  57. //Information about our functions...
  58. function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; cdecl; export;
  59. begin
  60.   case x of
  61.     0:begin
  62.         ProcAddr := @TIAThing;
  63.         StrPCopy(ProcDef, 'function TIAThing(Arr:TIntArray): TIntArray; cdecl;');
  64.       end;
  65.   else
  66.     x := -1;
  67.   end;
  68.   Result := x;
  69. end;
  70.  
  71.  
  72. exports GetPluginABIVersion;
  73. exports SetPluginMemManager;
  74. exports GetFunctionCount;
  75. exports GetFunctionInfo;
  76. exports OnDetach;
  77.  
  78. begin
  79. end.
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. //=================================================================================================\\
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. program new;
  104. type TIntArray = TIntegerArray;
  105. {$loadlib project1.dll}
  106.  
  107.  
  108. var
  109.   i:Int32;
  110.   v,a:TIntArray;
  111. begin
  112.   SetLength(v, 10000000);
  113.   for i:=0 to 5 do
  114.   begin
  115.     a := TIAThing(v);
  116.   end;
  117. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement