library DLLLib; { Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. } uses SysUtils, Classes; type TWektor = record x,y : Integer; end; function dodaj_wektory(const a , b : TWektor) : TWektor;stdcall; var wynik: TWektor; begin wynik.x:=a.x+b.x; wynik.y:=a.y+b.y; Result:=wynik; end; function odejmij_wektory (const a , b : TWektor) : TWektor;stdcall; var wynik: TWektor; begin wynik.x:=a.x-b.x; wynik.y:=a.y-b.y; Result:=wynik; end; procedure wyswietl_wektor(const a : TWektor);stdcall; begin writeln('[',a.x,',',a.y,']'); end; exports //tutaj jest spis eksportowanych funkcji dodaj_wektory index 1, odejmij_wektory index 2, wyswietl_wektor index 3; begin //instrukcje inicjalizujace end. ----------------------------------------------------------------------- program UsingDLLLib; {$apptype console} uses SysUtils, classes, windows; type TWektor = record x,y : Integer; end; var handler : HModule; wektor1, wektor2,wektor3: TWektor; wynik:TWektor; //deklaracje funkcji importowanych dodaj: function (const a, b : TWektor) : TWektor; stdcall; odejmij: function (const a,b : TWektor) : TWektor; stdcall; wyswietl : procedure(const a : TWektor); stdcall; begin handler:=Loadlibrary('DLLLib.dll'); if handler<>0 then begin //jesli nie udalo sie odczytac biblioteki z dysku, to handler=0. dodaj:=GetProcAddress(handler,PChar(1)); odejmij:=GetProcAddress(handler,PChar(2)); wyswietl:=GetProcAddress(handler,PChar(3)); wektor1.x:=5; wektor1.y:=7; wektor2.x:=5; wektor2.y:=7; wynik:=dodaj(wektor1,wektor2); wyswietl(wynik); wektor3.x:=4; wektor3.y:=4; wynik:=odejmij(wynik,wektor3); wyswietl(wynik); //jakies tam operacje z wykorzystaniem funkcji zaimportowanych, //na wektorach wektorl i wektor2. FreeLibrary(handler); //usuniecie biblioteki z PAO readln; end else begin writeln('Nie moge znalezc potrzebnej biblioteki!'); readln; end; end.