init
This commit is contained in:
parent
d5ec6494be
commit
7240505bd1
10 changed files with 128 additions and 1 deletions
32
src/dlopen.c
Normal file
32
src/dlopen.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include "dlopen.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
struct hotwire_dll_t hw_dlopen(const char *file, int flags) {
|
||||
|
||||
struct hotwire_dll_t dll;
|
||||
|
||||
// UNIX specific code(MacOS uses the same API as linux for dlopen)
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
dll.dll_handle = dlopen(file, flags);
|
||||
|
||||
if (dll.dll_handle == NULL){
|
||||
printf("could not load dll(UNIX api call returned error)\n");
|
||||
printf("error message: %s\n", dlerror());
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Windows specific code
|
||||
#if defined(_WIN32)
|
||||
dll.dll_handle = LoadLibrary(file);
|
||||
|
||||
if (!dll.dll_handle){
|
||||
printf("could not load dll(windows api call returned error)\n");
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
return dll;
|
||||
}
|
37
src/dlopen.h
Normal file
37
src/dlopen.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define HW_MODE 0
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
#define HW_MODE 1
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define HW_MODE 2
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
struct hotwire_dll_t {
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
void* dll_handle;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
HINSTANCE dll_handle;
|
||||
#endif
|
||||
};
|
||||
|
||||
// Function arguments are based off the dlopen() api on POSIX based operating systems
|
||||
// Loads dll from library
|
||||
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);
|
||||
|
||||
inline int hw_dlclose(void* handle);
|
Loading…
Add table
Add a link
Reference in a new issue