Recent

Author Topic: create win32 dll  (Read 4990 times)

loopbreaker

  • New Member
  • *
  • Posts: 32
create win32 dll
« on: March 04, 2014, 01:21:54 pm »
I have object files (COFF) which should be linked together to become a single win32 dll. For maximal performance, the object file functions should be directly callable by the dll user, that is, without (delegating) pascal implementations in the dll. Is this possible?

Fred vS

  • Hero Member
  • *****
  • Posts: 1675
    • miXimum is the DJ's best friend
Re: create win32 dll
« Reply #1 on: March 04, 2014, 01:39:17 pm »
Quote
Is this possible?

Yes, of course. The trick is to do your library the most simple it could. Do not export class, arrays, procedures of object. Use instead simple integers, strings or procedures.

What i do is using array of objects inside the dll. So if the user have to create a class or a object, it is done by the dll himself. Do not ask to the user to create class outside the library (mainly if the user is not a Pascal programmer).
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs

Leledumbo

  • Hero Member
  • *****
  • Posts: 8112
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: create win32 dll
« Reply #2 on: March 04, 2014, 04:06:55 pm »
If what you mean is that the dll will use the functions in the object file, but the functions themselves aren't exported by the dll:
http://www.freepascal.org/docs-html/prog/progsu145.html

loopbreaker

  • New Member
  • *
  • Posts: 32
Re: create win32 dll
« Reply #3 on: March 05, 2014, 03:36:47 am »
If I understand this, in the same library unit, now we need for each procedure:
1) declare as "external" (because implementation is in .o file)
2) the procedure name in the "exports" section (for users of dll)

This should create a dll to be a wrapper of the .o files.

Fred vS

  • Hero Member
  • *****
  • Posts: 1675
    • miXimum is the DJ's best friend
Re: create win32 dll
« Reply #4 on: March 05, 2014, 02:57:09 pm »
Hello.

Here how to create a dll :

1) the Library :
Code: [Select]
library mylibrary;

procedure myprocedure;  cdecl;
begin
/// your stuff...
end;

exports
myprocedure  name 'myprocedure' ;

end.

2) the wrapper-header for dynamically load the library :

Code: [Select]
unit mylibrary_h;

interface

uses
  DynLibs;

var
 myprocedure : procedure(); cdecl;
 LibHandle: TLibHandle = dynlibs.NilHandle;
function loadlib(const libfilename: String): boolean;
procedure unloadlib();

implementation

function loadlib(const libfilename: String): boolean;
begin
  Result := False;
    LibHandle := DynLibs.LoadLibrary(libfilename); // obtain the handle we want
    if LibHandle <> DynLibs.NilHandle then
    begin
     Pointer(myprocedure) := GetProcAddress(LibHandle, 'myprocedure');
    Result := true;
   end;
  end;

procedure unloadlib();
begin
      if LibHandle <> DynLibs.NilHandle then
  begin
    DynLibs.UnloadLibrary(LibHandle);
    LibHandle := DynLibs.NilHandle;
  end;
end;
end.

I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs