Hello. Such a question: there is an ехе , there is a dll №1 and there is a dll №2 . In the ехе load both libraries (using LoadLibrary , Main функции exported via extern "C" _declspec(dllexport) ), while in the Main функции first library are also loaded library number 2. That is, dll №2 loaded twice, I understand correctly?

My problem is that dll №1 loaded dll №2 , and it seems like I got the address of the exported function from dll №2 ( GetProcAddress did not return 0). But the function can not be called - the crash of the program. (With exe -shnika function starts normally)

    1 answer 1

    Hmm, it smells like undefined behaviour or incorrect recognition of the true problem. In general, if a library is already present in memory (and the Windows memory manager maintains its own low-level log of modules loaded into the address space), then reloading it into the same virtual space should not be done (although it depends on the Windows version and LoadLibrary implementation) return the address of the already imported library.

    The approach you use is most likely wrong, but in order not to dive into your wilds, you can advise the following:

    1. Check the availability of the required library in memory before blindly calling LoadLibrary anywhere.
    2. Use LoadLibraryEx for safer loading DLL `s

    For debugging, I advise you to compare the addresses of any of the same imported functions before and after trying to re-import the second lib (aka after calling its DllMain, aka after executing LoadLibrary within 1 lib) in order to make sure that the function address table is not updated. , and retrying library loading does not affect memory status.

    • I found a problem. In the first dll it was necessary to call FreeLibrary after getting the address of the function, then call the function. I do not know how it helped, but it helped .. - Alessander Vogrik
    • Thanks for the answer, I will use LoadLibraryEx - Alexander Vogrik
    • @Aleksandr Vogrik, I advise you to be extremely careful and use the routine for loading and unloading dll within the same module, that is, free up resources where you captured them. Otherwise there will be many problems. - AseN
    • one
      understood, I will rethink my code. Thank! - Alexander Vogrik