[Lazarus] "Running" a library
pascaldragon at googlemail.com
Sat Sep 15 11:13:08 CEST 2012
On 14.09.2012 23:47, Mark Morgan Lloyd wrote:
> Juha Manninen wrote:
>> On Fri, Sep 14, 2012 at 10:34 PM, Mark Morgan Lloyd
>> <markMLl.lazarus at telemetry.co.uk> wrote:
>>> No, I was wondering about the extent to which a library could be defined
>>> such that it was also runnable as a program.
>> A library cannot be run alone.
>> However there 2 kinds of libraries: a dynamic library (.dll, .so) and
>> a static library.
>> You can test your library code by creating a program that links the
>> code statically, or uses its code units directly.
> I'm aware of the technology, I've been using it intermittently for 20
> years or so.
> /Why/ can't a library be run standalone? We're already at the position
> that an executable can decide whether it's been invoked from a shell or
> the GUI and behave as appropriate, so why can't it decide whether it's
> being run as a program or being initialised as a library?
A library and an application have different entry point signatures. Take
Windows for example. There the entry point for applications is
"procedure EntryPoint; stdcall;" while for DLLs it is "procedure
EntryPoint(aHinstance: PtrInt; aDLLReason: Word; aDLLParam: Pointer);
stdcall;". Additionally the entry point of a DLL is called multiple
times (once the process loads the library, every time a new thread is
created and destroyed and once the process unloads the library) while
the entry point of an application is only called once. Also AFAIK
Windows does not let you run binaries that are flagged as "DLL". That's
the reason why there is a program called "rundll32" ;) [though it
expects an exported function with a certain signature...]
More information about the Lazarus