What is GetModuleHandle?

When you call this function, you pass a zero-terminated string that specifies the name of an executable or DLL file loaded into the calling process’s address space. If the system finds the specified executable or DLL name, GetModuleHandle returns the base address where that executable or DLL;s file image is loaded.

How do I handle a DLL?

Implementing DllMain() and saving the hinstDLL argument value is by far the easiest way to get it. GetModuleHandle(“yourdllname”) should work too. Using VirtualQuery() on your DLL function’s address and casting the returned AllocationBase to HMODULE is yet another one.

Which of the following are types of load libraries?

A load library can be any of the following:

  • System library.
  • Private library.
  • Temporary library.

What is KERNEL32 DLL used for?

KERNEL32. DLL exposes to applications most of the Win32 base APIs, such as memory management, input/output (I/O) operations, process and thread creation, and synchronization functions. Many of these are implemented within KERNEL32.

What does getmodulehandle do in FreeLibrary?

GetModuleHandle, however, returns the handle to a mapped module without incrementing its reference count. Note that the reference count is used in FreeLibrary to determine whether to unmap the function from the address space of the process.

When does the getmodulehandle function succeed in Win32?

The GetModuleHandle function succeeds only if the DLL module is already mapped into the address space of the process by load-time linking or by a previous call to LoadLibrary or LoadLibraryEx. Unlike LoadLibrary or LoadLibraryEx, GetModuleHandle does not increment the module reference count.

How does getmodulehandle not increment module reference count?

Unlike LoadLibrary or LoadLibraryEx, GetModuleHandle does not increment the module reference count. The GetModuleFileName function retrieves the full path of the module associated with a handle returned by GetModuleHandle, LoadLibrary, or LoadLibraryEx.

What’s the difference between getmodulehandle and GetProcAddress?

The handles returned by GetModuleHandle and LoadLibrary can be used in the same functions—for example, GetProcAddress, FreeLibrary, or LoadResource. The difference between the two functions involves the reference count.