Win32 equivalent of dlopen(NULL, ...)

2.3k views Asked by At

Is there a simple equivalent to dlopen(NULL, ...) on Windows?

The behavior on POSIX (or at least Linux) is: the returned handle can be used to find exported symbols on the executable as well as on dependent shared objects. To put simply, following

void *lib = dlopen(NULL, RTLD_NOW);

doing dlsym(lib, "memcpy") will return the symbol for memcpy.

On win32, GetModuleHandle(NULL) is almost an equivalent, except that the set of dependent DLLs is not searched for symbols; GetProcAddress(lib, "memcpy") returns NULL.

Any idea? Note: of course, in my application, I don't want to merely access memcpy, but some more complicated symbol, and from a FFI.

1

There are 1 answers

0
Brecht Sanders On

You may want to check out https://github.com/dlfcn-win32/dlfcn-win32 which is a dlopen() implementation for Windows (using mentioned functions GetModuleHandle / GetProcAddress).