Quantcast
Channel: Chilkat Forum - latest questions
Viewing all articles
Browse latest Browse all 1061

delphi (DLL version) static DLL names

$
0
0

(possible to make feature request here ?)

linking to fixed DLLName like


function CkSFtp_Create: HCkSFtp; stdcall; ... implementation

function CkSFtp_Create; external DLLName;


is unhandy because of some reasons:

  1. the path must be in search path and you can't give a specific location f.e. in a config-file if needed for several applications in different paths.

  2. if the dll cannot be loaded the application will abort immediately without error message.

  3. if you need a certain functionality f.e. SFTP or MAIL just only in seldom concrete situations then only on first use of that will be nessary to load the DLL and link the DLL-Entries. But in the actual implementation the DLL is loaded on EVERY start which slows down the start of the application.

will there be any chance to switch this to dynamically loading ? f.e.


function    CkSFtp_Create: HCkSFtp;
procedure   CkSFtp_Dispose( handle: HCkSFtp);

...

implementation

uses chilkat_DLL_loader;

type

TFkt_CkSFtp_Create          =function   : HCkSFtp;      stdcall;
TFkt_CkSFtp_Dispose         =procedure( handle: HCkSFtp);       stdcall;

...

var

_lcl_init:Boolean = true;
_fkt_ptr_arr:   array [0..266] of Pointer;

function    _Map( k:Integer; n:String):Pointer;
begin
    Result:=    _fkt_ptr_arr[k];
    if Result = nil then begin
        Chilkat_GetProcedureAddress( Result, n);
        _fkt_ptr_arr[k]:=   Result;
    end;
end;

function        CkSFtp_Create: HCkSFtp;
begin
    Result:=    TFkt_CkSFtp_Create(_map( 0, 'CkSFtp_Create'))
        ( );
end;

procedure   CkSFtp_Dispose(
                                handle: HCkSFtp
                            );
begin
    TFkt_CkSFtp_Dispose(_map( 1, 'CkSFtp_Dispose'))
        ( handle);
end;

...


and in chilkat_DLL_loader something like:


function    Chilkat_CanUse:Boolean;

procedure   Chilkat_GetProcedureAddress(var P; ProcName: string);

implementation

uses windows, sysutils;

const

DLLPath = '...';

var ModuleName: String;

function        Chilkat_LoadModule:HModule;
var
    S:  String;
begin
    S:=             DLLPath;

{$ifdef Win32}

    ModuleName:=    S + '\ChilkatDelphiXE.dll';

{$else}

    ModuleName:=    S + '\ChilkatDelphiXE64.dll';

{$endif}

    Result:= GetModuleHandle(PChar(ModuleName));
    if Result = 0 then
        Result:= LoadLibrary(PChar(ModuleName));
end;

procedure   Chilkat_GetProcedureAddress(var P; ProcName: string);
var
    ModuleHandle: HMODULE;
begin
    if not Assigned(Pointer(P)) then begin
        ModuleHandle := Chilkat_LoadModule;
        if ModuleHandle = 0 then
            raise Exception.Create('Library not found: ' + ModuleName); // + ' ' + WLastError);
        Pointer(P) := GetProcAddress(ModuleHandle, PChar(ProcName));
        if not Assigned(Pointer(P)) then
            raise Exception.Create('Function not found: ' + ModuleName + '.' + ProcName);
    end;
end;

function        Chilkat_CanUse:Boolean;
begin
    Result:=    Chilkat_LoadModule <> 0;
end;

I transformed each chilkat source in that way, but I think it would be better chilkat will provide the dynamically loading if other users will also need that kind of loading (?)


Viewing all articles
Browse latest Browse all 1061

Trending Articles