int main()
{
int conSymmetricKeyMsg = 1;
switch(conSymmetricKeyMsg)
{
case 1:
//这个环境变量是定义动态库存在的路径
if(getenv("DLDIR") != NULL)
len = snprintf(dlName, sizeof(dlName), "%s/%s", getenv("DLDIR"), "libKeyUpdate.so");
else
len = snprintf(dlName, sizeof(dlName), "%s/bin/%s", getenv("REC"), "libKeyUpdate.so");
//获取动态库的名字(绝对路径)
dlName[len] = 0;
//打开动态库
if((dlHandle = dlopen(dlName, RTLD_NOW)) == NULL)
{
printf("in SynchTCPIPTaskServer:: dlopen[%s] error[%s]\n", dlName, dlerror());
ret = errCodeParameter;
break;
}
//用dlsym取得FunDLKeyUpdate 函数动态地址
if((FunDLKeyUpdate = dlsym(dlHandle, "UpdateKey")) == NULL)
{
printf("in UnionSynchTCPIPTaskServer:: dlsym[%s] error[%s]\n", "UnionUpdateKey", dlerror());
dlclose(dlHandle);
ret = errCodeParameter;
break;
}
//获取到动态库里面的函数之后就可以执行该函数了
if((ret = (*UnionFunDLKeyUpdate)((char *)buf+2)) < 0)
{
printf("in UnionSynchTCPIPTaskServer:: UnionFunDLKeyUpdate ret=[%d]\n", ret);
dlclose(dlHandle);
break;
}
//用dlclose关闭dlHandle 所指示的动态链接库
dlclose(dlHandle);
break;
}
}
阅读(925) | 评论(0) | 转发(0) |