mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-27 07:53:43 +02:00

Each port that allows the usage of dynamic libraries should call InitSystemDynLibs during initialization of the System unit. The DynLibs unit has been adjusted to be a forwarder for the functions that now reside in the System unit (for backwards compatiblity just in case). Additionally the unit will register the DynLibsManager if it doesn't reside in the System unit anyway. Currently only the Windows targets (Win32, Win64 and WinCE) implement the DynLibsManager inside the System unit. For other systems using the LoadLibrary, etc. functions will lead to a run error/exception. If a port wants to implement its own DynLibsManager then it needs to define DISABLE_NO_DYNLIBS_MANAGER. TLibHandle, NilHandle and optionally TOrdinalEntry (it's set to SizeUInt otherwise) should be defined in sysdlh.inc which needs to be enabled using the define FPC_SYSTEM_HAS_SYSDLH (because there are targets which have FEATURE_DYNLIBS enabled, but don't support them... e.g. powerpc-wii -.-). The DynLibsManager contains methods for loading a library based on a RawByteString and based on a UnicodeString. BOTH should be implemented, but internally one can forward to the other. The loading by ordinal *can* be be implemented. If it is set to Nil then the implementation of GetProcAddress(lib,ordinal) will return Nil. + new functions SetDynLibsManager and GetDynLibsManager to set and retrieve the current DynLibsManager * provide interface of DynLibs unit in unit System git-svn-id: trunk@29613 -
68 lines
2.6 KiB
PHP
68 lines
2.6 KiB
PHP
{
|
|
This file is part of the Free Pascal run time library.
|
|
Copyright (c) 1999-2015 by the Free Pascal development team
|
|
|
|
See the file COPYING.FPC, included in this distribution,
|
|
for details about the copyright.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
**********************************************************************}
|
|
|
|
{$ifdef FPC_SYSTEM_HAS_SYSDLH}
|
|
{$i sysdlh.inc}
|
|
{$else FPC_SYSTEM_HAS_SYSDLH}
|
|
{ These are fallback declarations }
|
|
type
|
|
TLibHandle = THandle;
|
|
|
|
const
|
|
NilHandle = TLibHandle(0);
|
|
{$endif FPC_SYSTEM_HAS_SYSDLH}
|
|
|
|
{ ---------------------------------------------------------------------
|
|
OS - Independent declarations.
|
|
---------------------------------------------------------------------}
|
|
type
|
|
{$if not declared(TOrdinalEntry)}
|
|
TOrdinalEntry = SizeUInt;
|
|
{$endif not declared(TOrdinalEntry)}
|
|
|
|
TLoadLibraryUHandler = function(const Name: UnicodeString): TLibHandle;
|
|
TLoadLibraryAHandler = function(const Name: RawByteString): TLibHandle;
|
|
TGetProcAddressHandler = function(Lib: TLibHandle; const ProcName: AnsiString): Pointer;
|
|
TGetProcAddressOrdinalHandler = function(Lib: TLibHandle; Ordinal: TOrdinalEntry): Pointer;
|
|
TUnloadLibraryHandler = function(Lib: TLibHandle): Boolean;
|
|
TGetLoadErrorStrHandler = function: String;
|
|
|
|
TDynLibsManager = record
|
|
LoadLibraryU: TLoadLibraryUHandler;
|
|
LoadLibraryA: TLoadLibraryAHandler;
|
|
GetProcAddress: TGetProcAddressHandler;
|
|
GetProcAddressOrdinal: TGetProcAddressOrdinalHandler;
|
|
UnloadLibrary: TUnloadLibraryHandler;
|
|
GetLoadErrorStr: TGetLoadErrorStrHandler;
|
|
end;
|
|
|
|
Function SafeLoadLibrary(const Name : RawByteString) : TLibHandle;
|
|
Function LoadLibrary(const Name : RawByteString) : TLibHandle;
|
|
Function SafeLoadLibrary(const Name : UnicodeString) : TLibHandle;
|
|
Function LoadLibrary(const Name : UnicodeString) : TLibHandle;
|
|
|
|
Function GetProcedureAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer;
|
|
Function GetProcedureAddress(Lib : TLibHandle; Ordinal: TOrdinalEntry) : Pointer;
|
|
Function UnloadLibrary(Lib : TLibHandle) : Boolean;
|
|
Function GetLoadErrorStr: string;
|
|
|
|
// Kylix/Delphi compability
|
|
|
|
Function FreeLibrary(Lib : TLibHandle) : Boolean; inline;
|
|
Function GetProcAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer; inline;
|
|
|
|
Procedure GetDynLibsManager (Var Manager : TDynLibsManager);
|
|
Procedure SetDynLibsManager (Const New : TDynLibsManager);
|
|
Procedure SetDynLibsManager (Const New : TDynLibsManager; Var Old: TDynLibsManager);
|
|
|