Way to create a DLL ? lazarus / 13-General ---------------------------------------------------------------------- tibo · 2004-09-10 14:31 Hello ! Is it possible to create DLLs in order to create plug-ins for my application ? And how to do that ? Thanks for your answers. ---------------------------------------------------------------------- Drewski · 2004-09-10 14:51 Code: [Select] library mydll; {$mode objfpc}{$H+} uses   Classes, SysUtils;  type  TMyType = object; function Init(): MyType; cdecl; export; begin   //do stuff   Result := TMyType.Create; end; procedure CountAlot(HowHigh: Integer); cdecl; export; var x: Integer; begin   for x := 0 to howhigh do     writeln(x); end; function Close(): Integer; cdecl; export; begin   //do stuff   Result := 400000; end; exports    Init name 'MYLIB_INIT',    CountALot name 'MYLIB_COUNTALOT',    Close name 'MYLIB_CLOSE'; end; then to use in a unit add something like this in a unit before implementation type   TMyType = object; function MYLIB_Init(): TMYType; cdecl; external 'mydll' name 'MYLIB_INIT'; etc. HTH Andrew; ---------------------------------------------------------------------- Lightning · 2004-09-14 13:48 There is a demo included with Lazarus in the FPC sources in the demo subfolder: On windows the C:\lazarus\pp directory. On linux the /usr/fpcsrc directory. ---------------------------------------------------------------------- Adam.Pilorz · 2004-10-05 17:24 Hmm... Yes, but is that possible, to load those dinamicaly (is that right?)? I mean to load them while running the program, to enable creating plug-ins? When you load DLL's staticly you can't use it to create plugins, as you must know their names on develop level. ---------------------------------------------------------------------- Lightning · 2004-10-05 19:32 You can link static or dinamic for a dinamic example see the OpenGL units (gl, glu, glut) Have a look at dllfuncs, but for OpenGL on Linux you might need to make a simple modification: you should add 'const RTLD_GLOBAL = $100' and in function LoadLibrary change 'Result := THandle(dlopen(Name, RTLD_LAZY));' to 'Result := THandle(dlopen(Name, RTLD_LAZY or RTLD_GLOBAL ));' If you only need to work in windows then you could load a dll just like in Delphi. ---------------------------------------------------------------------- Anonymous · 2004-12-27 20:29 Hmm, and what's with the dynamic DLL loading? Using @ operator for procedure variable occures an error (only in Lazarus, Free Pascal compiles it). Can you tell me how can I repair it? PS. Sorry for my English ---------------------------------------------------------------------- Lightning · 2004-12-29 12:05 What Operating System are you using ? Try with the latest CVS version. ---------------------------------------------------------------------- Anonymous · 2005-01-31 17:18 DLL dont work !!! bug 655 //The test lib library testlib; uses Classes,SysUtils; function lib_test(a,b:integer):integer;cdecl; begin result:=a+b; end; exports lib_test; begin end. //test_interface.pas unit test_interface; interface function lib_test(a,b:integer):integer;cdecl; implementation function lib_test;external 'libtestlib.so'; begin end. in console application all works OK. in lcl application when I add to uses test_interface (no more code) I get on app close. An unhandled exception occurred at 0x00000000 : EAccessViolation : Access violation $00000000 An unhandled exception occurred at 0x00000000 : EAccessViolation : Access violation $00000000 ... in indefenet loop. when dll(so) or testApplication compiled in Kylix3 then all OK.