Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program test_call_lib;
- type
- TLibReport = (LibOK, LibUnkown, LibNoMethod);
- function CallProc(const idLib, idProc : string) : TLibReport;
- const
- LIBEXT = {$ifdef windows} '.dll' {$else} '.so' {$endif}
- type
- TProc = procedure; stdcall;
- var
- dll : Cardinal;
- proc : TProc;
- begin
- CallProc := LibOK;
- dll := LoadLibrary(idLib + LIBEXT);
- if dll <> 0 then begin
- @proc := GetProcAddress(dll, idProc);
- if Assigned(proc) then
- proc
- else
- CallProc := LibNoMethod;
- FreeLibrary(dll);
- end else
- CallProc := LibUnknown;
- end;
- begin
- case CallProc('libexample', 'foo') of
- LibOK : writeln('[Done]');
- LibUnknown : writeln('Library not found');
- LibNoMethod : writeln('Library doesn''t have the method.');
- end;
- {$ifdef windows} readln; {$endif} // pause for Windows
- end.
Advertisement
Add Comment
Please, Sign In to add comment