1

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.

Jarhmander
  • 344
  • 5
  • 19
  • 1
    This looks like it should answer your question: [**Get address for symbol in current process in Windows**](https://stackoverflow.com/questions/45114078/get-address-for-symbol-in-current-process-in-windows) – Andrew Henle Jul 03 '20 at 13:32
  • 1
    I've found a likely duplicate: https://stackoverflow.com/questions/23437007/getprocaddress-with-all-loaded-libraries – Jarhmander Jul 03 '20 at 16:04

1 Answers1

2

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).

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40