Skip to content

Instantly share code, notes, and snippets.

@huangered
Created September 26, 2019 10:23
Show Gist options
  • Save huangered/8cdf72d53191051d52a259ecbd5d2f98 to your computer and use it in GitHub Desktop.
Save huangered/8cdf72d53191051d52a259ecbd5d2f98 to your computer and use it in GitHub Desktop.
c shared load macro
#ifdef __linux__
#include <dlfcn.h>
#define LIBTYPE void*
#define OPENLIB(libname) dlopen((libname), RTLD_LAZY)
#define LIBFUNC(lib, fn) dlsym((lib), (fn))
#define FREELIB(lib) dlclose((lib))
#elif defined(_WIN32)
#include <Windows.h>
#define LIBTYPE HINSTANCE
#define OPENLIB(libname) LoadLibraryW(L ## libname)
#define LIBFUNC(lib, fn) GetProcAddress((lib), (fn))
#define FREELIB(lib) FreeLibrary((lib))
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment