Using the function LoadLibraryEx included client.dll library. I need to get the address of the client.dll file using the GetModuleHandle function.

HMODULE library = LoadLibraryEx("D://libs//client.dll",NULL, LOAD_LIBRARY_AS_DATAFILE); 

GetModuleHandle (??);

As I include the library variable in the arguments of the getmodulehandle function, it just won't work, because the data type is completely different and gives an error. Or maybe I misunderstood something, and after LoadLibraryEx you do not need to use getmodulehandle.

  • one
    And why do you need GetModuleHandle ? You came from HMODULE LoadLibraryEx . - VladD
  • By the way, why LOAD_LIBRARY_AS_DATAFILE ? For what purpose do you need a library? - VladD
  • Those. getmodulehandle and loadlibraryex identical? - Dimcheg
  • @VladD, the library is needed in order to get its address, adding to the addresses of certain values ​​from the process. As a result, getting a static address, because the address of the value that I need is changing. - Dimcheg
  • one
    Well, why not just read the documentation for GetModuleHandle and LoadLibraryEx ? Quote: GetModuleHandle function Retrieves a module handle for the specified module. The module must have been loaded by the calling process. Return Value: This is a handle to the specified module. - VladD

1 answer 1

Okay, in order to get the base address of the module in memory, you need to use the MODULEINFO structure, in which it is contained.

MODULEINFO can get the MODULEINFO structure using GetModuleInformation by GetModuleInformation it the handle to the module ( HMODULE ). The handle itself can be obtained either during the loading of the module ( LoadLibraryEx ), or if the module is already loaded, and you have not saved the handle, via GetModuleHandleEx .


Specification: Please note, you will need to load a module without the LOAD_LIBRARY_AS_DATAFILE flag! Otherwise, GetModuleInformation will not work .

  • @Dimcheg: updated answer - VladD
  • What then is used in the flasg argument? Null - Dimcheg
  • Even when I remove this flag, the application requires other DLL libraries that client.dll apparently requires - Dimcheg
  • @Dimcheg: Yeah, yes. Because for the correct initialization of this module itself, other libraries, apparently, are needed. - VladD
  • @Dimcheg: Maybe you want to pass LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR or there LOAD_LIBRARY_SEARCH_APPLICATION_DIR . - VladD