dlsym
This commit is contained in:
parent
92bc02b3a5
commit
9798f880f9
|
@ -1,5 +1,5 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
void test(){
|
void test(){
|
||||||
printf("testing 123\n");
|
printf("testing 123(unix)\n");
|
||||||
}
|
}
|
|
@ -1,6 +1,12 @@
|
||||||
#include "../../src/dlopen.h"
|
#include "../../src/dlopen.h"
|
||||||
|
|
||||||
|
typedef void (*func_handle)();
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
struct hotwire_dll_t dll = hw_dlopen("./bin/exampleUnixLib.dll", RTLD_NOW);
|
struct hotwire_dll_t dll = hw_dlopen("./bin/exampleUnixLib.dll", RTLD_NOW);
|
||||||
|
|
||||||
|
func_handle func = (func_handle)hw_dlsym(dll, "test");
|
||||||
|
|
||||||
|
func();
|
||||||
}
|
}
|
|
@ -1,6 +1,12 @@
|
||||||
#include "../../src/dlopen.h"
|
#include "../../src/dlopen.h"
|
||||||
|
|
||||||
|
typedef void (*func_handle)();
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
struct hotwire_dll_t dll = hw_dlopen("./bin/exampleWinLib.dll", 0);
|
struct hotwire_dll_t dll = hw_dlopen("./bin/exampleWinLib.dll", 0);
|
||||||
|
|
||||||
|
func_handle func = (func_handle)hw_dlsym(dll, "test");
|
||||||
|
|
||||||
|
func();
|
||||||
}
|
}
|
10
src/dlopen.c
10
src/dlopen.c
|
@ -30,3 +30,13 @@ struct hotwire_dll_t hw_dlopen(const char *file, int flags) {
|
||||||
|
|
||||||
return dll;
|
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
|
||||||
|
}
|
|
@ -2,17 +2,14 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#define HW_MODE 0
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
#define HW_MODE 1
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define HW_MODE 2
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -32,6 +29,6 @@ struct hotwire_dll_t {
|
||||||
struct hotwire_dll_t hw_dlopen(const char* file, int flags);
|
struct hotwire_dll_t hw_dlopen(const char* file, int flags);
|
||||||
|
|
||||||
// Loads symbol from DLL
|
// 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);
|
||||||
|
|
Loading…
Reference in a new issue