i have encountered problems when translating a pascal procedure (which uses libc functions :: dlopen , dlsym and dlclose) into c source ... hint and direct me to the solution(preferably with smaller simpler c code examples) ...
below is the pascal code , i try to implement it in a
self-contained pascal procedure with only one "includes"("uses" in pascal) libc at somewhere else ... it might not be the "correct" way of coding it but i managed to just compile and run the whole app , just run ...
Code:
procedure TForm1.Button3Click(Sender: TObject);
type
TGTKModuleHandle=Pointer;
const
NIL_MODULEHANDLE=TGTKModuleHandle(NIL);
var
s:string;
lib_name,func_name:pchar;
call_func: function(pass_strings:Pchar):Pchar;cdecl ;
GTKModuleHandle:TGTKModuleHandle;
begin
if GTKModuleHandle <> NIL_MODULEHANDLE then
dlclose(GTKModuleHandle);
GTKModuleHandle:=NIL_MODULEHANDLE;
lib_name:='libcallgtk02.so';
GTKModuleHandle:=dlopen(lib_name,RTLD_NOW);
try
if GTKModuleHandle <> NIL_MODULEHANDLE then
begin
// char *call_gtk02(char *pass_strings); in libcallgtk02.so
func_name:='call_gtk02';
call_func:= dlsym(GTKModuleHandle,func_name);
s:=call_func('dlopen strings to here ...');
memo1.lines.add('return from dlopen ----> '+s);
end else
begin
showmessage('cant locate your function ...');
exit;
end ;
finally
if GTKModuleHandle <> NIL_MODULEHANDLE then
dlclose(GTKModuleHandle);
end ;//end try
end;
note :: its a kylix/pascal gui with a button and a text-memo gadget and by clicking the button , it call a function came "packaged" in a shared library which run a gtk app(but modal window) , the name(in strings) of the library and the function have been known beforehand , can have a look at the shared library here :: HERE ...
//thanks in advance ...
.