Recent

Author Topic: Way to create a DLL ?  (Read 7043 times)

tibo

  • Guest
Way to create a DLL ?
« on: September 10, 2004, 04:31:46 pm »
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

  • Jr. Member
  • **
  • Posts: 55
Way to create a DLL ?
« Reply #1 on: September 10, 2004, 04:51:01 pm »
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

  • Sr. Member
  • ****
  • Posts: 422
Way to create a DLL ?
« Reply #2 on: September 14, 2004, 03:48:52 pm »
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.
The future must be... Fast and OpenSource so...
Think Open and Lightning Fast!

Adam.Pilorz

  • Jr. Member
  • **
  • Posts: 67
    • http://www.pilotmp3.devtown.net
Way to create a DLL ?
« Reply #3 on: October 05, 2004, 07:24:01 pm »
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

  • Sr. Member
  • ****
  • Posts: 422
Way to create a DLL ?
« Reply #4 on: October 05, 2004, 09:32:41 pm »
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.
The future must be... Fast and OpenSource so...
Think Open and Lightning Fast!

Anonymous

  • Guest
Way to create a DLL ?
« Reply #5 on: December 27, 2004, 09:29:24 pm »
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

  • Sr. Member
  • ****
  • Posts: 422
Way to create a DLL ?
« Reply #6 on: December 29, 2004, 01:05:04 pm »
What Operating System are you using ?
Try with the latest CVS version.
The future must be... Fast and OpenSource so...
Think Open and Lightning Fast!

Anonymous

  • Guest
Way to create a DLL ?
« Reply #7 on: January 31, 2005, 06:18:23 pm »
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.

 

TinyPortal © 2005-2018