#include
#include "log_def.h"
INT DLL_RUN (Char * DLL, Char * Func, Const Char * PFormat, ...) {void * functionLib; / * handle to shared lib file * / int (* function) (); / * Pointer to loaded routine * / Const char * DLERROR; / * POINTER TO ERROR STRING * / CHAR DLL_FILE [128]; / * Dynamic Library * / int R; / * Return Code * / CHAR Para [256]; / * Parameters * /
VA_LIST AP_LIST;
/ * Load dynamic library * / MEMSET (DLL_FILE, 0x00, SIZEOF (DLL_FILE)); if ("DLL_PATH", DLL_FILE) {Write_log (Error_Log, "% s |% D: Error: Do Not Find item DLL_PATH! ", __ file __, __ line__); return -1;} strcat (dll_file," / "); strcat (dll_file, dll);
/ * LOAD DLL * / FUNCTIONLIB = DLOPEN (DLL_FILE, RTLD_LAZY); DLERROR = DLERROR (); if (DLERROR) {Write_log (Error_Log, "% S |% D: Dopen Error:% S", __ file __, __ line __, dLerror) Return (-1);}
/ * Load function * / function = DLSYM (FunctionLib, FUNC); DLERROR = DLERROR (); if (DLERROR) {WRITE_LOG (Error_Log, "% s |% D: DLSYM Error:% S", __ file __, __ line __, dLerror) ; / * Close DLL Handle * / DLClose (FunctionLib); Return (-1);}
VA_Start (ap_list, pformat);
/ * Run * / MEMSET (PARA, 0x00, SIZEOF (PARA); vSprintf (PARA, PFORMAT, AP_LIST); RET = (* function) (PARA); if (re) {DLERROR = DLERROR (); Write_log (Error_log , "% s |% D: Run Error:% s", __ file __, __ line __, dLerror);
VA_END (AP_LIST); DLClose (FunctionLib); if (re) Return -1; Else Return 0;
/ ************************************************** // * int main () {DLL_Run ("DLL.SO", "P", "% s |% s |% s |", "1", "2f2", "3"); // DLL_Run (" Dll.so "," p "," ");
Return 0;} * /