On 03/19/2016 08:29 PM, fredvs wrote:
>> dlopen, dlsym and dlerror are *functions*, not console commands. Well, I
>> never tried the latter, but it appears they are not on your system ;-)
>> Now, I don't know where exactly these functions are declared (in which
>> unit, that is), but for debugging purposes, just add
>>    Function dlopen(filename: PChar; flags: cint): Pointer; cdecl;
>> external;
>>    Function dlclose(handle: Pointer): cint; cdecl; external;
>>    Function dlsym(handle: Pointer; Name: PChar): Pointer; cdecl; external;
>>    Function dlerror: PChar; cdecl; external;
>> Somewhere in your code before you call them. 
> Ooops, thanks for answer but now I am completely loosed... ;-(
>
> So  those functions can be used in fpc code?
> If so, must a library be loaded to access that functions (and what library)?
> Or are those functions defined in a fpc unit ?

See Marco's answer. So instead of using the above declarations, a simple
`Uses dl;` should do the trick.

As to how to use them, now you do something like this:
    X:= GetProcedureAddress(...);
    Y:= GetProcedureAddress(...);
    Z:= GetProcedureAddress(...);

When one of these fails, a nil pointer is returned. dlerror will give
you more info on what failed where. So, if you know X returns nil for
some-yet-to-be-determined-reason, place the dlerror immediately after that:
    X:= GetProcedureAddress(...);
    WriteLn(dlerror);
    Y:= GetProcedureAddress(...);
    Z:= GetProcedureAddress(...);

Of course, you could choose to do something like this if you do not know
which call exactly fails:
    X:= GetProcedureAddress(...);
    If X = nil Then
        WriteLn('Z: ', dlerror);
    Y:= GetProcedureAddress(...);
    If Y = nil Then
        WriteLn('Y: ', dlerror);
    Z:= GetProcedureAddress(...);
    If Z = nil Then
        WriteLn('Z: ', dlerror);

It is really nothing more than a function call, quite similar to fpGetErrNo.


> I am in the dark.

Being in the dark is positive, as one can always turn on the lights :-)

-- 
Ewald


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to