How to find in a DLL which process loaded it?

I am updating a DLL module that acts as a kind of plugin for a Windows application.

This plugin is compatible with different versions of the same software line. Now, for a specific function, I have to access the configuration files of the parent software. Since different versions of the software have them in different places, I have to figure out which version loads the DLL. Individual versions are easily recognized by the process executable name (that is, abc_v1.exe, abc_v2.exe, abc_v3.exe).

Is there a way to get the name of the process loading the dll? I use C ++ with some basic WinAPI commands, but not with ATL, MFC or such.

I am currently testing parent software using its own SDK features, but this requires opening a connection. Depending on the contents of the DLL configuration files, there is no need to open a connection, so I would like to know which version downloaded it before establishing a connection.

+6
source share
1 answer

Call GetModuleFileName , passing NULL as the module descriptor. In the documentation:

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

+5
source

Source: https://habr.com/ru/post/958798/


All Articles