mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-13 13:09:16 +02:00
+ defaultfilesystemcodepage support for dynlibs
+ unicodestring overloads for (safe)loadlibrary() git-svn-id: branches/cpstrrtl@25162 -
This commit is contained in:
parent
acb27f726a
commit
3fdb3092af
@ -20,6 +20,8 @@ unit dynlibs;
|
||||
|
||||
interface
|
||||
|
||||
{$i rtldefs.inc}
|
||||
|
||||
{ ---------------------------------------------------------------------
|
||||
Read OS-dependent interface declarations.
|
||||
---------------------------------------------------------------------}
|
||||
@ -33,8 +35,11 @@ interface
|
||||
---------------------------------------------------------------------}
|
||||
|
||||
|
||||
Function SafeLoadLibrary(const Name : AnsiString) : TLibHandle;
|
||||
Function LoadLibrary(const Name : AnsiString) : TLibHandle;
|
||||
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 UnloadLibrary(Lib : TLibHandle) : Boolean;
|
||||
Function GetLoadErrorStr: string;
|
||||
@ -55,19 +60,11 @@ Implementation
|
||||
|
||||
{$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;
|
||||
{$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;
|
||||
@ -82,11 +79,7 @@ Function SafeLoadLibrary(const Name : AnsiString) : TLibHandle;
|
||||
{$endif cpui386}
|
||||
ssecw:=GetSSECSR;
|
||||
{$endif}
|
||||
{$if defined(windows) or defined(win32)}
|
||||
Result:=LoadLibraryA(PChar(Name));
|
||||
{$else}
|
||||
Result:=loadlibrary(Name);
|
||||
{$endif}
|
||||
Result:=doloadlibrary(Name);
|
||||
finally
|
||||
{$if defined(cpui386) or defined(cpux86_64)}
|
||||
Set8087CW(fpucw);
|
||||
@ -98,5 +91,67 @@ Function SafeLoadLibrary(const Name : AnsiString) : TLibHandle;
|
||||
end;
|
||||
end;
|
||||
|
||||
{$ifndef FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
|
||||
Function SafeLoadLibrary(const Name : RawByteString) : TLibHandle;
|
||||
begin
|
||||
Result:=DoSafeLoadLibrary(UnicodeString(Name));
|
||||
end;
|
||||
|
||||
Function LoadLibrary(const Name : RawByteString) : TLibHandle;
|
||||
begin
|
||||
Result:=DoLoadLibrary(UnicodeString(Name));
|
||||
end;
|
||||
|
||||
{$else not FPCRTL_FILESYSTEM_SINGLE_BYTE_API}
|
||||
|
||||
Function SafeLoadLibrary(const Name : RawByteString) : TLibHandle;
|
||||
begin
|
||||
Result:=DoSafeLoadLibrary(ToSingleByteFileSystemEncodedFileName(Name));
|
||||
end;
|
||||
|
||||
Function LoadLibrary(const Name : RawByteString) : TLibHandle;
|
||||
begin
|
||||
Result:=DoLoadLibrary(ToSingleByteFileSystemEncodedFileName(Name));
|
||||
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;
|
||||
begin
|
||||
Result:=DoLoadLibrary(ToSingleByteFileSystemEncodedFileName(Name));
|
||||
end;
|
||||
|
||||
{$else not FPCRTL_FILESYSTEM_TWO_BYTE_API}
|
||||
|
||||
Function SafeLoadLibrary(const Name : UnicodeString) : TLibHandle;
|
||||
begin
|
||||
Result:=DoSafeLoadLibrary(Name);
|
||||
end;
|
||||
|
||||
Function LoadLibrary(const Name : UnicodeString) : TLibHandle;
|
||||
begin
|
||||
Result:=DoLoadLibrary(Name);
|
||||
end;
|
||||
{$endif not FPCRTL_FILESYSTEM_TWO_BYTE_API}
|
||||
|
||||
|
||||
Function FreeLibrary(Lib : TLibHandle) : Boolean;
|
||||
|
||||
begin
|
||||
Result:=UnloadLibrary(lib);
|
||||
end;
|
||||
|
||||
Function GetProcAddress(Lib : TlibHandle; const ProcName : AnsiString) : Pointer;
|
||||
|
||||
begin
|
||||
Result:=GetProcedureAddress(Lib,Procname);
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
@ -36,10 +36,10 @@ Const
|
||||
|
||||
Uses nwserv;
|
||||
|
||||
Function LoadLibrary(const Name : AnsiString) : TlibHandle;
|
||||
var args : array[0..1] of pchar;
|
||||
Function DoLoadLibrary(const Name : RawByteString) : TlibHandle;
|
||||
var args : array[0..1] of PAnsiChar;
|
||||
begin
|
||||
args[0] := pchar(Name);
|
||||
args[0] := PAnsiChar(Name);
|
||||
args[1] := nil;
|
||||
Result:=spawnvp(P_NOWAIT,@args,nil);
|
||||
end;
|
||||
|
@ -35,10 +35,10 @@ Const
|
||||
|
||||
uses libc;
|
||||
|
||||
Function LoadLibrary(const Name : AnsiString) : TLibHandle;
|
||||
Function DoLoadLibrary(const Name : RawByteString) : TLibHandle;
|
||||
|
||||
begin
|
||||
Result:=dlopen(Pchar(Name),RTLD_LAZY);
|
||||
Result:=dlopen(PAnsiChar(Name),RTLD_LAZY);
|
||||
end;
|
||||
|
||||
Function GetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;
|
||||
|
@ -41,13 +41,13 @@ threadvar
|
||||
DynLibErrNo: cardinal;
|
||||
DynLibErrPath: array [0..259] of char;
|
||||
|
||||
function LoadLibrary (const Name: AnsiString): TLibHandle;
|
||||
function DoLoadLibrary (const Name: RawbyteString): TLibHandle;
|
||||
var
|
||||
Handle: longint;
|
||||
begin
|
||||
DynLibErrPath [0] := #0;
|
||||
DynLibErrNo := DosLoadModule (@DynLibErrPath [0], SizeOf (DynLibErrPath),
|
||||
PChar (Name), Handle);
|
||||
PAnsiChar (Name), Handle);
|
||||
if DynLibErrNo = 0 then
|
||||
Result := Handle
|
||||
else
|
||||
|
@ -42,24 +42,26 @@ Const
|
||||
|
||||
uses dl;
|
||||
|
||||
Function LoadLibrary(const Name : AnsiString) : TLibHandle;
|
||||
Function DoLoadLibrary(const Name : RawByteString) : TLibHandle;
|
||||
{$ifdef aix}
|
||||
var
|
||||
MemberName: AnsiString;
|
||||
MemberName: RawByteString;
|
||||
{$endif}
|
||||
begin
|
||||
{$ifndef aix}
|
||||
Result:=TLibHandle(dlopen(Pchar(Name),RTLD_LAZY));
|
||||
Result:=TLibHandle(dlopen(PAnsiChar(Name),RTLD_LAZY));
|
||||
{$else aix}
|
||||
{ in aix, most shared libraries are static libraries (archives) that contain
|
||||
a single object: shr.o for 32 bit, shr_64.o for 64 bit. You have to specify
|
||||
this object file explicitly via the RTLD_MEMBER member flag }
|
||||
{$ifdef cpu64}
|
||||
MemberName:=Name+'(shr_64.o)';
|
||||
MemberName:='(shr_64.o)';
|
||||
{$else cpu64}
|
||||
MemberName:=Name+'(shr.o)';
|
||||
MemberName:='(shr.o)';
|
||||
{$endif cpu64}
|
||||
Result:=TLibHandle(dlopen(Pchar(MemberName),RTLD_LAZY or RTLD_MEMBER));
|
||||
SetCodePage(MemberName,DefaultFileSystemCodePage,false);
|
||||
MemberName:=Name+MemberName;
|
||||
Result:=TLibHandle(dlopen(PAnsiChar(MemberName),RTLD_LAZY or RTLD_MEMBER));
|
||||
{$endif aix}
|
||||
end;
|
||||
|
||||
|
@ -36,10 +36,10 @@ Const
|
||||
|
||||
Uses windows;
|
||||
|
||||
Function LoadLibrary(const Name : AnsiString) : TlibHandle;
|
||||
Function DoLoadLibrary(const Name : UnicodeString) : TlibHandle;
|
||||
|
||||
begin
|
||||
Result:=Windows.LoadLibrary(PChar(Name));
|
||||
Result:=Windows.LoadLibraryW(PWideChar(Name));
|
||||
end;
|
||||
|
||||
Function GetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;
|
||||
|
@ -36,13 +36,9 @@ Const
|
||||
|
||||
Uses windows;
|
||||
|
||||
Function LoadLibrary(const Name : AnsiString) : TlibHandle;
|
||||
var
|
||||
ws: PWideChar;
|
||||
Function DoLoadLibrary(const Name : UnicodeString) : TlibHandle;
|
||||
begin
|
||||
ws:=StringToPWideChar(Name);
|
||||
Result:=Windows.LoadLibrary(ws);
|
||||
FreeMem(ws);
|
||||
Result:=Windows.LoadLibrary(PWideChar(Name));
|
||||
end;
|
||||
|
||||
Function GetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;
|
||||
|
Loading…
Reference in New Issue
Block a user