diff --git a/examples/unix/lib.c b/examples/unix/lib.c index e3f6573..8c088ff 100644 --- a/examples/unix/lib.c +++ b/examples/unix/lib.c @@ -1,5 +1,5 @@ #include void test(){ - printf("testing 123\n"); + printf("testing 123(unix)\n"); } \ No newline at end of file diff --git a/examples/unix/main.c b/examples/unix/main.c index d2f98d9..c59edbd 100644 --- a/examples/unix/main.c +++ b/examples/unix/main.c @@ -1,6 +1,12 @@ #include "../../src/dlopen.h" +typedef void (*func_handle)(); + int main() { struct hotwire_dll_t dll = hw_dlopen("./bin/exampleUnixLib.dll", RTLD_NOW); + + func_handle func = (func_handle)hw_dlsym(dll, "test"); + + func(); } \ No newline at end of file diff --git a/examples/win/main.c b/examples/win/main.c index d709de1..5ecd03f 100644 --- a/examples/win/main.c +++ b/examples/win/main.c @@ -1,6 +1,12 @@ #include "../../src/dlopen.h" +typedef void (*func_handle)(); + int main() { struct hotwire_dll_t dll = hw_dlopen("./bin/exampleWinLib.dll", 0); + + func_handle func = (func_handle)hw_dlsym(dll, "test"); + + func(); } \ No newline at end of file diff --git a/src/dlopen.c b/src/dlopen.c index a22c98e..c711929 100644 --- a/src/dlopen.c +++ b/src/dlopen.c @@ -29,4 +29,14 @@ struct hotwire_dll_t hw_dlopen(const char *file, int flags) { #endif return dll; +} + +void* hw_dlsym(struct hotwire_dll_t dll, const char* symbol){ + #if defined(_WIN32) + return GetProcAddress(dll.dll_handle, symbol); + #endif + + #if defined(__linux) || defined(__APPLE__) + return dlsym(dll.dll_handle, symbol); + #endif } \ No newline at end of file diff --git a/src/dlopen.h b/src/dlopen.h index 0b0fdd5..87b9097 100644 --- a/src/dlopen.h +++ b/src/dlopen.h @@ -2,17 +2,14 @@ #include #if defined(__APPLE__) -#define HW_MODE 0 #include #endif #if defined(__linux__) -#define HW_MODE 1 #include #endif #if defined(_WIN32) -#define HW_MODE 2 #include #endif @@ -32,6 +29,6 @@ struct hotwire_dll_t { struct hotwire_dll_t hw_dlopen(const char* file, int flags); // Loads symbol from DLL -inline void* hw_dlsym(struct hotwire_dll_t dll, const char *__restrict symbol); +void* hw_dlsym(struct hotwire_dll_t dll, const char* symbol); -inline int hw_dlclose(void* handle); +int hw_dlclose(void* handle);