Linux 上写C++(8) 如何调用动态库
#include <stdio.h>
#include <dlfcn.h>
#include <iostream>
using namespace std;
typedef int (*IVR_HTTP_Server)(
char *V_INTERFACE_NAME,
char *V_SERIAL_NUMBER,
char *V_PARAM,
char *V_ResultCode,
char *V_Field1,
char *V_Field2,
char *V_Field3,
char *V_Field4,
char *V_Field5,
char *O_Result
);
void Do_QHAI_UNHQ_CCScoreInfo()
{
void *myhandle;
//加载动态库
myhandle=dlopen("./IVR_HTTP_Server.so",RTLD_LAZY);//open lib file
IVR_HTTP_Server HTTP_Request=(IVR_HTTP_Server)dlsym(myhandle,"HTTP_Request");
dlerror();
char V_INTERFACE_NAME[200]="IVR_ITF_YUN_TEST";
char V_SERIAL_NUMBER[20]="13800000000";
//char V_PARAM[7024]="qwe||rtyu||iopasd||fghjko||ewue";
char V_ResultCode[100]="respCode";
char V_Field1[100]="VALUE";
char V_Field2[100]="";
char V_Field3[100]="";
char V_Field4[100]="";
char V_Field5[100]="";
char O_Result[7024]="";
HTTP_Request(
V_INTERFACE_NAME,
V_SERIAL_NUMBER,
V_PARAM,
V_ResultCode,
V_Field1,
V_Field2,
V_Field3,
V_Field4,
V_Field5,
O_Result);
dlclose(myhandle);
dlerror();
cout<<"------------------------response--------------------------------------------"<<endl;
cout<<"\n V_INTERFACE_NAME:>>>>>>>>>>>>>"<<V_INTERFACE_NAME<<endl;
cout<<"\n V_SERIAL_NUMBER:>>>>>>>>>>>>>"<<V_SERIAL_NUMBER<<endl;
cout<<"\n V_PARAM:>>>>>>>>>>>>>"<<V_PARAM<<endl;
cout<<"\n V_ResultCode:>>>>>>>>>>>>>"<<V_ResultCode<<endl;
cout<<"\n V_Field1:>>>>>>>>>>>>>"<<V_Field1<<endl;
cout<<"\n V_Field2:>>>>>>>>>>>>>"<<V_Field2<<endl;
cout<<"\n V_Field3:>>>>>>>>>>>>>"<<V_Field3<<endl;
cout<<"\n V_Field4:>>>>>>>>>>>>>"<<V_Field4<<endl;
cout<<"\n V_Field5:>>>>>>>>>>>>>"<<V_Field5<<endl;
cout<<"\n O_Result:>>>>>>>>>>>>>"<<O_Result<<endl;
}
int main(int argc,int argv[]){
Do_QHAI_UNHQ_CCScoreInfo();
return 0;
}