-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlproc.h
executable file
·60 lines (53 loc) · 1.01 KB
/
dlproc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef __DL_PROC_H__
#define __DL_PROC_H__
#include "xmlproc.h"
#include <dlfcn.h>
class dlproc: public xmlproc
{
public:
void *dp;
char *error;
typedef int (*onLoader_ft)(dlproc * dlproc);
onLoader_ft onLoader;
dlproc(const char * dlfile)
{
dp = dlopen(dlfile, RTLD_LAZY); /* 打开动态链接库 */
if (dp == NULL) /* 若打开失败则退出 */
{
fputs(dlerror(), stderr);
exit(1);
}
}
void doLoader()
{
UnDoneProc();
onLoader = (onLoader_ft) dlsym(dp, "onLoader");
error = dlerror(); /* 检测错误 */
if (error) /* 若出错则退出 */
{
printf("dlerror::%s\r\n", error);
exit(1);
}
int ret = onLoader(this); /* 调用此共享函数 */
DoneProc();
}
~dlproc()
{
printf("dlproc exit\r\n");
dlclose(dp); /* 关闭共享库 */
printf("dlproc exit OK\r\n");
}
};
//
//dlproc * OpenDlProc(const char * name)
//{
// typedef dlproc * (*init_fn)();
// void *dp;
// char *error;
// init_fn init;
//
// dlproc *
// ret->dp = dp;
// return ret;
//}
#endif //__DL_PROC_H__