summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/test/library/ttdllexe.pp
blob: 1a384e1457483ffd463d10be00968f254a8a4823 (plain)
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
{ %target=win32,win64 }
{ %needlibrary }
{

  Win32 DLL usage example. It needs testdll2.pp
  This test checksq the windows abality to
  export a function in an executable.

  Here procedure TestExeProc is exported
  and is imported by testdll2 DLL.

}

program ttdllexe;

uses
  Windows;

procedure test; external 'testdll2' name 'test';
function GetString : string; external 'testdll2' name 'GetString';

var
   s : string;external 'testdll2' name 'teststr';
const
  called : boolean = false;

procedure TestExeProc;export;
begin
  Writeln('Main: TestExeProc');
  Writeln('Main: S is: "',s,'"');
  called:=true;
end;

exports
  TestExeProc;

begin
  s:='Before test call';
  Writeln('Main: S is: "',GetString,'"');
  if (s<>GetString) then
    begin
      Writeln('Error in DLL variable handling');
      halt(1);
    end;
  test;
  Writeln('Main: S value after call is: "',s,'"');
  if not called then
    begin
      Writeln('Error in DLL variable handling');
      halt(1);
    end;

end.