blob: e9d368f11b3e16c8e022e9a40d078e3f1757f036 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
{
This file is part of the Free Pascal run time library.
Copyright (c) 1999-2000 by the Free Pascal development team
Implements OS-independent loading of dynamic libraries.
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}
{$MODE OBJFPC}
{$ENDIF}
unit dynlibs;
interface
{ ---------------------------------------------------------------------
Read OS-dependent interface declarations.
---------------------------------------------------------------------}
{$define readinterface}
{$i dynlibs.inc}
{$undef readinterface}
{ ---------------------------------------------------------------------
OS - Independent declarations.
---------------------------------------------------------------------}
Function SafeLoadLibrary(const Name : AnsiString) : TLibHandle;
Function LoadLibrary(const Name : AnsiString) : TLibHandle;
Function GetProcedureAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer;
Function UnloadLibrary(Lib : TLibHandle) : Boolean;
Function GetLoadErrorStr: string;
// Kylix/Delphi compability
Function FreeLibrary(Lib : TLibHandle) : Boolean;
Function GetProcAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer;
Type
HModule = TLibHandle;
Implementation
{ ---------------------------------------------------------------------
OS - Independent declarations.
---------------------------------------------------------------------}
{$i dynlibs.inc}
Function FreeLibrary(Lib : TLibHandle) : Boolean;
begin
Result:=UnloadLibrary(lib);
end;
Function GetProcAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer;
begin
Result:=GetProcedureAddress(Lib,Procname);
end;
Function SafeLoadLibrary(const Name : AnsiString) : TLibHandle;
{$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:=GetSSECSR;
{$endif}
{$if defined(windows) or defined(win32)}
Result:=LoadLibraryA(PChar(Name));
{$else}
Result:=loadlibrary(Name);
{$endif}
finally
{$if defined(cpui386) or defined(cpux86_64)}
Set8087CW(fpucw);
{$ifdef cpui386}
if has_sse_support then
{$endif cpui386}
SetSSECSR(ssecw);
{$endif}
end;
end;
end.
|