1{
2    This file is part of the Free Pascal run time library.
3    Copyright (c) 1999-2000 by the Free Pascal development team
4
5    Implements OS dependent part for loading of dynamic libraries.
6
7    See the file COPYING.FPC, included in this distribution,
8    for details about the copyright.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 **********************************************************************}
15
16
17Function SysLoadLibraryU(const Name : UnicodeString) : TlibHandle;
18
19begin
20  Result:=WinLoadLibraryW(PWideChar(Name));
21end;
22
23Function SysLoadLibraryA(const Name: RawByteString) : TLibHandle;
24
25begin
26  Result:=WinLoadLibraryW(PWideChar(UnicodeString(Name)));
27end;
28
29Function SysGetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;
30
31begin
32  Result:=WinGetProcAddress(Lib,PChar(ProcName));
33end;
34
35{$push}
36{$warn 4056 off}
37Function SysGetProcedureAddressOrdinal(Lib : TLibHandle; Ordinal : TOrdinalEntry) : Pointer;
38
39begin
40  Result:=WinGetProcAddress(Lib,PChar(Ordinal));
41end;
42{$pop}
43
44Function SysUnloadLibrary(Lib : TLibHandle) : Boolean;
45
46begin
47  Result:=WinFreeLibrary(Lib);
48end;
49
50Function SysGetLoadErrorStr: string;
51
52Var
53  rc,c : integer;
54  temp: WideString;
55begin
56  rc := GetLastError;
57  SetLength(temp,255);
58  C:=FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,nil,rc,
59                 MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
60                 @temp[1], 255,nil);
61  SetLength(temp,c);
62  Result:=AnsiString(temp);
63end;
64
65const
66  SysDynLibsManager: TDynLibsManager = (
67    LoadLibraryU: @SysLoadLibraryU;
68    LoadLibraryA: @SysLoadLibraryA;
69    GetProcAddress: @SysGetProcedureAddress;
70    GetProcAddressOrdinal: @SysGetProcedureAddressOrdinal;
71    UnloadLibrary: @SysUnloadLibrary;
72    GetLoadErrorStr: @SysGetLoadErrorStr;
73  );
74
75procedure InitSystemDynLibs;
76begin
77  SetDynLibsManager(SysDynLibsManager);
78end;
79