Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the name of a DLL from within the dll

Tags:

c++

c

windows

If I have a dll called "foo.dll" and the end user renames it to "bar.dll". After calling to a LoadLibrary, how can I get the name "bar.dll" from inside my dll?

Is it GetModuleFileName(hModule, buffer); ?

like image 736
Clark Gaebel Avatar asked May 17 '09 11:05

Clark Gaebel


People also ask

How do I identify a DLL?

You can list function names for a specific DLL, such as user32. dll, by running a variety of command-line tools. For example, you can use dumpbin /exports user32. dll or link /dump /exports user32.

How do I find the DLL path?

Your DLL files are located in C:\Windows\System32. When Windows Defender runs a Full Scan, it includes that directory and so all of your DLLs will be scanned.

What functions are in a DLL?

A DLL helps promote developing modular programs. It helps you develop large programs that require multiple language versions or a program that requires modular architecture. An example of a modular program is an accounting program that has many modules that can be dynamically loaded at run time.

How are DLLs loaded?

DLL files may be explicitly loaded at run-time, a process referred to simply as run-time dynamic linking by Microsoft, by using the LoadLibrary (or LoadLibraryEx ) API function. The GetProcAddress API function is used to look up exported symbols by name, and FreeLibrary – to unload the DLL.


1 Answers

yes, you need to store hModule in DllMain

BOOL WINAPI DllMain(HINSTANCE hinstDLL,  DWORD fdwReason,  LPVOID lpvReserved)
{
  switch (fdwReason)
  {
    case DLL_PROCESS_ATTACH:
      hModule = hinstDLL;
      break;
  }
}
like image 125
Shay Erlichmen Avatar answered Oct 05 '22 05:10

Shay Erlichmen