Reputation: 116
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.
Upvotes: 6
Views: 5490
Reputation: 612784
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.
Upvotes: 6