|
@@ -20,156 +20,95 @@ unit dynlibs;
|
|
|
|
|
|
interface
|
|
interface
|
|
|
|
|
|
-{$i rtldefs.inc}
|
|
|
|
-
|
|
|
|
-{ ---------------------------------------------------------------------
|
|
|
|
- Read OS-dependent interface declarations.
|
|
|
|
- ---------------------------------------------------------------------}
|
|
|
|
|
|
+Type
|
|
|
|
+ TLibHandle = System.TLibHandle;
|
|
|
|
|
|
-{ Note: should define the TOrdinalEntry type and define
|
|
|
|
- DYNLIBS_SUPPORTS_ORDINAL if the operating system supports loading
|
|
|
|
- functions by a ordinal like e.g. Windows or OS/2 do }
|
|
|
|
|
|
+Const
|
|
|
|
+ NilHandle = System.NilHandle;
|
|
|
|
+ SharedSuffix = System.SharedSuffix;
|
|
|
|
|
|
-{$define readinterface}
|
|
|
|
-{$i dynlibs.inc}
|
|
|
|
-{$undef readinterface}
|
|
|
|
|
|
+Function SafeLoadLibrary(const Name : RawByteString) : TLibHandle; inline;
|
|
|
|
+Function LoadLibrary(const Name : RawByteString) : TLibHandle; inline;
|
|
|
|
+Function SafeLoadLibrary(const Name : UnicodeString) : TLibHandle; inline;
|
|
|
|
+Function LoadLibrary(const Name : UnicodeString) : TLibHandle; inline;
|
|
|
|
|
|
-{ ---------------------------------------------------------------------
|
|
|
|
- OS - Independent declarations.
|
|
|
|
- ---------------------------------------------------------------------}
|
|
|
|
-{$IFNDEF DYNLIBS_SUPPORTS_ORDINAL}
|
|
|
|
-type
|
|
|
|
- TOrdinalEntry = SizeUInt;
|
|
|
|
-{$ENDIF DYNLIBS_SUPPORTS_ORDINAL}
|
|
|
|
-
|
|
|
|
-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;
|
|
|
|
|
|
+Function GetProcedureAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer; inline;
|
|
|
|
+Function GetProcedureAddress(Lib : TLibHandle; Ordinal: TOrdinalEntry) : Pointer; inline;
|
|
|
|
+Function UnloadLibrary(Lib : TLibHandle) : Boolean; inline;
|
|
|
|
+Function GetLoadErrorStr: string; inline;
|
|
|
|
|
|
// Kylix/Delphi compability
|
|
// Kylix/Delphi compability
|
|
|
|
|
|
-Function FreeLibrary(Lib : TLibHandle) : Boolean;
|
|
|
|
-Function GetProcAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer;
|
|
|
|
|
|
+Function FreeLibrary(Lib : TLibHandle) : Boolean; inline;
|
|
|
|
+Function GetProcAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer; inline;
|
|
|
|
|
|
Type
|
|
Type
|
|
HModule = TLibHandle;
|
|
HModule = TLibHandle;
|
|
|
|
|
|
Implementation
|
|
Implementation
|
|
|
|
|
|
-{ ---------------------------------------------------------------------
|
|
|
|
- OS - Independent declarations.
|
|
|
|
- ---------------------------------------------------------------------}
|
|
|
|
|
|
|
|
-{ Note: should define the TOrdinalEntry overload if the operating system
|
|
|
|
- supports loading functions by a ordinal like e.g. Windows or OS/2 do }
|
|
|
|
|
|
+{ Should define a procedure InitDynLibs which sets up the DynLibs manager; optionally a
|
|
|
|
+ DoneDynLibs can be defined which is called during finalization }
|
|
{$i dynlibs.inc}
|
|
{$i dynlibs.inc}
|
|
|
|
|
|
-{$ifndef FPCRTL_FILESYSTEM_TWO_BYTE_API}
|
|
|
|
-Function DoSafeLoadLibrary(const Name : RawByteString) : TLibHandle;
|
|
|
|
-{$else not FPCRTL_FILESYSTEM_TWO_BYTE_API}
|
|
|
|
-Function DoSafeLoadLibrary(const Name : UnicodeString) : TLibHandle;
|
|
|
|
-{$endif not FPCRTL_FILESYSTEM_TWO_BYTE_API}
|
|
|
|
-{$if defined(cpui386) or defined(cpux86_64)}
|
|
|
|
- var
|
|
|
|
- fpucw : Word;
|
|
|
|
- ssecw : DWord;
|
|
|
|
-{$endif}
|
|
|
|
- begin
|
|
|
|
- try
|
|
|
|
-{$if defined(cpui386) or defined(cpux86_64)}
|
|
|
|
- fpucw:=Get8087CW;
|
|
|
|
-{$ifdef cpui386}
|
|
|
|
- if has_sse_support then
|
|
|
|
-{$endif cpui386}
|
|
|
|
- ssecw:=GetMXCSR;
|
|
|
|
-{$endif}
|
|
|
|
- Result:=doloadlibrary(Name);
|
|
|
|
- finally
|
|
|
|
-{$if defined(cpui386) or defined(cpux86_64)}
|
|
|
|
- Set8087CW(fpucw);
|
|
|
|
-{$ifdef cpui386}
|
|
|
|
- if has_sse_support then
|
|
|
|
-{$endif cpui386}
|
|
|
|
- SetMXCSR(ssecw);
|
|
|
|
-{$endif}
|
|
|
|
- end;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
-{$ifndef FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
|
|
|
|
Function SafeLoadLibrary(const Name : RawByteString) : TLibHandle;
|
|
Function SafeLoadLibrary(const Name : RawByteString) : TLibHandle;
|
|
begin
|
|
begin
|
|
- Result:=DoSafeLoadLibrary(UnicodeString(Name));
|
|
|
|
|
|
+ Result:=System.SafeLoadLibrary(Name);
|
|
end;
|
|
end;
|
|
|
|
|
|
Function LoadLibrary(const Name : RawByteString) : TLibHandle;
|
|
Function LoadLibrary(const Name : RawByteString) : TLibHandle;
|
|
begin
|
|
begin
|
|
- Result:=DoLoadLibrary(UnicodeString(Name));
|
|
|
|
|
|
+ Result:=System.LoadLibrary(Name);
|
|
end;
|
|
end;
|
|
|
|
|
|
-{$else not FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
|
|
|
|
-
|
|
|
|
-Function SafeLoadLibrary(const Name : RawByteString) : TLibHandle;
|
|
|
|
|
|
+Function SafeLoadLibrary(const Name : UnicodeString) : TLibHandle;
|
|
begin
|
|
begin
|
|
- Result:=DoSafeLoadLibrary(ToSingleByteFileSystemEncodedFileName(Name));
|
|
|
|
|
|
+ Result:=System.SafeLoadLibrary(Name);
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function LoadLibrary(const Name : RawByteString) : TLibHandle;
|
|
|
|
|
|
+Function LoadLibrary(const Name : UnicodeString) : TLibHandle;
|
|
begin
|
|
begin
|
|
- Result:=DoLoadLibrary(ToSingleByteFileSystemEncodedFileName(Name));
|
|
|
|
|
|
+ Result:=System.LoadLibrary(Name);
|
|
end;
|
|
end;
|
|
-{$endif not FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
|
|
|
|
|
|
|
|
|
|
|
|
-{$ifndef FPCRTL_FILESYSTEM_TWO_BYTE_API}
|
|
|
|
-Function SafeLoadLibrary(const Name : UnicodeString) : TLibHandle;
|
|
|
|
-begin
|
|
|
|
- Result:=DoSafeLoadLibrary(ToSingleByteFileSystemEncodedFileName(Name));
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-Function LoadLibrary(const Name : UnicodeString) : TLibHandle;
|
|
|
|
|
|
+Function GetProcedureAddress(Lib : TLibHandle; const ProcName: AnsiString) : Pointer;
|
|
begin
|
|
begin
|
|
- Result:=DoLoadLibrary(ToSingleByteFileSystemEncodedFileName(Name));
|
|
|
|
|
|
+ Result:=System.GetProcedureAddress(Lib, ProcName);
|
|
end;
|
|
end;
|
|
|
|
|
|
-{$else not FPCRTL_FILESYSTEM_TWO_BYTE_API}
|
|
|
|
-
|
|
|
|
-Function SafeLoadLibrary(const Name : UnicodeString) : TLibHandle;
|
|
|
|
|
|
+Function GetProcedureAddress(Lib : TLibHandle; Ordinal : TOrdinalEntry) : Pointer;
|
|
begin
|
|
begin
|
|
- Result:=DoSafeLoadLibrary(Name);
|
|
|
|
|
|
+ Result:=System.GetProcedureAddress(Lib, Ordinal);
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function LoadLibrary(const Name : UnicodeString) : TLibHandle;
|
|
|
|
|
|
+Function UnloadLibrary(Lib : TLibHandle) : Boolean;
|
|
begin
|
|
begin
|
|
- Result:=DoLoadLibrary(Name);
|
|
|
|
|
|
+ Result:=System.UnloadLibrary(Lib);
|
|
end;
|
|
end;
|
|
-{$endif not FPCRTL_FILESYSTEM_TWO_BYTE_API}
|
|
|
|
|
|
|
|
-{$ifndef DYNLIBS_SUPPORTS_ORDINAL}
|
|
|
|
-{ OS does not support loading by ordinal (or it's not implemented yet), so by
|
|
|
|
- default we simply return Nil }
|
|
|
|
-Function GetProcedureAddress(Lib : TLibHandle; Ordinal : TOrdinalEntry) : Pointer;
|
|
|
|
|
|
+Function GetLoadErrorStr: String;
|
|
begin
|
|
begin
|
|
- Result := Nil;
|
|
|
|
|
|
+ Result:=System.GetLoadErrorStr;
|
|
end;
|
|
end;
|
|
-{$endif not DYNLIBS_SUPPORTS_ORDINAL}
|
|
|
|
|
|
|
|
Function FreeLibrary(Lib : TLibHandle) : Boolean;
|
|
Function FreeLibrary(Lib : TLibHandle) : Boolean;
|
|
|
|
|
|
begin
|
|
begin
|
|
- Result:=UnloadLibrary(lib);
|
|
|
|
|
|
+ Result:=System.FreeLibrary(lib);
|
|
end;
|
|
end;
|
|
|
|
|
|
Function GetProcAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer;
|
|
Function GetProcAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer;
|
|
|
|
|
|
begin
|
|
begin
|
|
- Result:=GetProcedureAddress(Lib,Procname);
|
|
|
|
|
|
+ Result:=System.GetProcedureAddress(Lib,Procname);
|
|
end;
|
|
end;
|
|
|
|
|
|
-
|
|
|
|
|
|
+initialization
|
|
|
|
+ InitDynLibs;
|
|
|
|
+finalization
|
|
|
|
+{$if declared(DoneDynLibs)}
|
|
|
|
+ DoneDynLibs;
|
|
|
|
+{$endif}
|
|
end.
|
|
end.
|