//========================================================== //Fun_UserAppAlg 用户算法入口 //用户的算法在此实现 //========================================================== BYTE UserAppAlg(BYTE xdata *RxComm,BYTE xdata *TxComm) { BYTE cmd; cmd = RxComm[1]; if (cmd == 0x00) { GlobalVar_Init(); //全局变量的初始化 } if (cmd == 0x01) { test_fun1(RxComm , TxComm); } if (cmd == 0x02) { test_fun2(RxComm,TxComm); } if (cmd == 0x03) { test_fun3(TxComm); } if (cmd == 0x04) { test_fun4(TxComm); } return 1; }
int main(int argc, char **argv) { char *error = NULL; void *handle = NULL; void (*fun1)(); typedef char *(*fun2)(char *); // load so file handle = dlopen("/huaixiaoz/ospdf/code.so",RTLD_LAZY); error = dlerror(); if(error != NULL) { printf("Fail to load so file.\n[%s]\n",error); return -1; } //get function address fun1 = (void (*))dlsym(handle,"fun1"); error = dlerror(); if (error != NULL) { printf("Fail to get functiom address.\n[%s]\n",error); return -1; } // implement the function fun1(); // get function address fun2 test_fun2 = (fun2)dlsym(handle,"fun2"); error = dlerror(); if (error != NULL) { printf("Fail to get function address.\n[%s]]n",error); return -1; } // implement the function char test[10] = "test.so"; char *test_return = test_fun2(test); printf("%s\n",test_return); // decrease amount of reference dlclose(handle); return 0; }