> Could someone give me an idea? I am writing an application to which I
> hope to add functionality later. One option would be to simple send out
> the new exe to all users. However, I would like to implement a plugin
> system. So a new feature could simply be added and totaly integrated to
> the original application. It is important to note that the application
> has no idea what is going to be added later.
>
> Any ideas anyone?
>

Notes:
If you want people to build plug-ins in other languages than Pascal (visual
basic, C++, C, etc) then don't use ansistrings or objects since they are
specific to Pascal.
Who is your market? People who own copies of Delphi/FPC or people who own copies
of Visual Studio, Delphi, VB, FPC, and more?

If using a DLL system and you want to export ansistrings from a DLL you can use
a memory manager trick similar to the trick being used in Pascal Server Pages
1.6.X project.

The memory manager trick to export ansistrings from a DLL is:

program MySoftware;

// export memory manager from executable (software hosting the plug-ins)
procedure ExportMemMan(out MemMan: TMemoryManager); stdcall;
begin
  GetMemoryManager(MemMan);
end;

function TestAPI: string;
begin
  result:= 'hello, this is the API in the exe ';
end;

exports
  ExportMemMan name 'GetSharedMemMan',
  TestApi;

begin
end.


library MyPlugin;

var
  GetExternalMemMan: procedure(MemMan: TMemoryManager);
  TestApi: function: string;
  MemMan: TMemoryManger; //storage of received mem manager
begin
  // get handle of EXE
  ExeHandle:= loadlibrary('yourprogram.exe');
  // import exe memory manager into DLL plug-in
  GetExternalMemMan:= getprocaddress(ExeHandle, 'GetSharedMemMan');
  GetExternalMemMan(MemMan);
  SetMemoryManager(MemMan);
  // You can now use ansistrings in dll

  TestApi:= getprocaddress(ExeHandle, 'TestApi');
  showmessage( TestApi() );
end.

Above ansistring memory manager trick should work with FPC and Delphi plug-ins,
which means Delphi developers and FPC developers will be able to make plug-ins
for your program, not just fpc developers.

The most powerful plug in systems have communication systems both held inside
the exectuable and the dll. Many people make the mistake of thinking only the
DLL can export, when in fact the program itself can contain an API of it's own
that is exported which the DLL can talk to. A simple example plug-in system that
uses an API held inside the EXE is implemented in LazarusRB in plugger_api.pas

If it is objects that you need to export then you can make procedural wrappers
that export each and every procedure/variable from that class, then reimport
them with a wrapper again. Take a look at LazarusRB sources for an example of
that system in plugger_api.pas and PluggerWrapper.pas.

Or of course you also can wait until fpc is able to export BPL style packages,
which again will only work with FPC and not plug ins built with Delphi or other
languages like C/C++/VB. It depends on your needs and the type of program it is.

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to