-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtestlib.c
50 lines (40 loc) · 1.25 KB
/
testlib.c
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
#include <agar/core.h>
#include <SDL2/SDL.h>
#include <stdio.h>
#include <stdlib.h>
void* getFunctionPointer(void* lib, const char* funcName) {
//
// Get the function pointer to the function
void* fptr = SDL_LoadFunction(lib, funcName);
if (!fptr) {
fprintf(stderr, "Could not get function pointer for %s\n error is: %s\n", funcName, SDL_GetError());
return NULL;
}
return fptr;
}
int main(int argc, char** argv)
{
char moduleName[128] = "";
//
// Declare the function pointers:
void (*fptr_null )(int);
void (*fptr_ModuleName)(char*, void*);
//
// Open the dynamic library
void* hdd_lib = SDL_LoadObject(argv[1]);
if (!hdd_lib) {
//
// Apparently, the library could not be opened
fprintf(stderr, "Could not open %s\n", argv[1]);
fprintf(stderr, "%s\n", SDL_GetError());
exit(1);
}
//
// Get the pointers to the functions within the library:
fptr_null =getFunctionPointer(hdd_lib, "doesNotExist");
fptr_ModuleName=getFunctionPointer(hdd_lib, argv[2]);
if (fptr_ModuleName) fptr_ModuleName(moduleName, NULL);
fprintf(stderr, "Module name : %s\n", moduleName);
extern AG_Object agDrivers;
fprintf(stderr, "&agDrivers %p\n", &agDrivers);
}