summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/webtbs/tw7838b.pp
blob: 2088fc4ff68e4381385816285e8d87b9f2d566f4 (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,linux}

program prog;
{$mode objfpc}

uses
  popuperr,
  dynlibs;

// this function is exported from the EXE
function exetest: longint; {public name 'exetest';}
begin
  writeln('exe test');
  result:=5;
end;

exports
  exetest name 'exetest';

const
{$ifdef unix}
{$ifdef darwin}
  libname = './libtw7838a.dylib';
{$else}
  libname = './libtw7838a.so';
{$endif}
{$endif}
{$ifdef windows}
  libname = 'tw7838a.dll';
{$endif}

var
  dllf: function: longint;
  lh: tlibhandle;

begin

  lh:= loadlibrary(libname); // load dyn.so (unix) or dyn.dll (ms windows)
  if lh = nilhandle then
    begin
      writeln('dyn library returned nil handle');
      halt(1);
    end;
  pointer(dllf):= getprocaddress(lh, 'dllf'); // get function from dll

  // call function in dll, which calls function in exe, and then prints
  // a result number 5
  if (dllf()<>5) then
    halt(1);
  writeln(dllf());
  writeln('end of program');
  freelibrary(lh);
end.