Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find in a DLL which process loaded it?

Tags:

c++

dll

winapi

I am refining a DLL module that acts as a sort of plugin for a Windows application.

This plugin is compatibile with various versions of a single software line. Now, for a certain functionality, I have to access the configuration files of the parent software. Since different versions of the software have these in different places, I have to find out which version loads the DLL. The separate versions are readily discernable by the process executable name (i.e. abc_v1.exe, abc_v2.exe, abc_v3.exe).

Is there a way to get the name of the process that loaded the DLL? I am using C++ with some basic WinAPI commands, but not ATL, MFC or such.

Currently I am polling the parent software by use of it's own SDK functions, but that requires opening a connection. Depending on content of the configuration files, the DLL does not need to open a connection, so I would like to know which version loaded it before having to establish communication.

like image 807
Fabo.sk Avatar asked Nov 25 '13 20:11

Fabo.sk


People also ask

How can I tell which process is using a DLL?

Process Explorer has a facility that allows you to search through the currently running processes for a specific file. To perform this search go to Find -> Find Handle or DLL... and then enter the name of the file you are interested in. Save this answer. Show activity on this post.

How do I find DLL details?

You can retrieve the information by using a program, or by using Windows Explorer as follows: Select the DLL with the right mouse button. Select Properties from the pop-up menu. Select the Version tab.

What loaded DLL?

The DLL. Load method loads a particular dynamic link library in TestComplete and returns a pointer to the library. Later, this pointer can be used to call routines from the dll. Before you load a dll, you should define its type and type of its functions using the DLL.

How do I view DLLs in Process Explorer?

Running Process ExplorerOn the View menu, make sure Show Lower Pane is checked. Press CTRL+D or select View > Lower Pane View > DLLs to enable DLL view mode.


1 Answers

Call GetModuleFileName passing NULL as the module handle. From the documentation:

A handle to the loaded module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path of the executable file of the current process.

like image 91
David Heffernan Avatar answered Sep 24 '22 12:09

David Heffernan