Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GetModuleFileName

3 views
Skip to first unread message

Dave Navarro

unread,
Aug 11, 1998, 3:00:00 AM8/11/98
to
Is there any way to use GetModuleFileName to get the name of the EXE or DLL
which loaded your DLL?

My DLL needs to know the name/path of the module which loaded it.

--Dave

Jan K. Avlasov

unread,
Aug 12, 1998, 3:00:00 AM8/12/98
to

Not under win32 (i'm prepared to be corrected here).
You may get PID of the process loaded your library and then use
toolhelp library (under win95)
or PSAPI (or whatever it is under NT) to retreive process information by
PID. If anyone get a better way please post it.

Yan

PJ Naughter

unread,
Aug 12, 1998, 3:00:00 AM8/12/98
to

INCORRECT. From the docs:


GetModuleFileName
The GetModuleFileName function retrieves the full path and filename
for the executable file containing the specified module.

Windows 95: The GetModuleFilename function will return long filenames
when an application's version number is greater than or equal to 4.00
and the long filename is available. Otherwise, it returns only 8.3
format filenames.

DWORD GetModuleFileName(
HMODULE hModule, // handle to module to find filename for
LPTSTR lpFilename, // pointer to buffer to receive module path
DWORD nSize // size of buffer, in characters
);

Parameters
hModule
Handle to the module whose executable filename is being requested. If
this parameter is NULL, GetModuleFileName returns the path for the
file used to create the calling process.

So to state if you call GetModuleFilename with NULL you will get the
name of the EXE which loaded it.


Regards,


'''
@ @
+========================ooO-(_)-Ooo=================================+
| PJ Naughter |
| |
| Software Developer Email: p...@indigo.ie |
| Softech Telecom URL: http://indigo.ie/~pjn |
| |
+====================================================================+


Dave Navarro

unread,
Aug 12, 1998, 3:00:00 AM8/12/98
to
In article <35d45f4d....@news.eunet.ie>, p...@indigo.ie says...

> On Wed, 12 Aug 1998 13:45:23 +0600, "Jan K. Avlasov"
> <avl...@inp.nsk.su> wrote:
>
> So to state if you call GetModuleFilename with NULL you will get the
> name of the EXE which loaded it.

You are a genius. Pure genius. Thanks!

--Dave

Hector Santos

unread,
Aug 13, 1998, 3:00:00 AM8/13/98
to dave navarro

On Aug 11, 1998 12:10pm, DA...@POWERBASIC.COM (DAVE NAVARRO) wrote to ALL:


DN> Is there any way to use GetModuleFileName to get the name of the EXE or
DN> DLL which loaded your DLL?

DN> My DLL needs to know the name/path of the module which loaded it.

hmmmm, suppose you have two programs:

process1.exe
process2.exe

and both processes shared a common DLL. If you use GetModuleFileName()
in the DLL_ATTACH_PROCESS with the NULL parameter, it will give you
the idea that BOTH loaded the DLL. In other words, when process1.exe
loads the DLL, the entry point is called and you can then call
the GetModuleFileName and you will get process1.exe. But the same
thing will occur with process2.exe. When it loads the DLL, it too
will return process2.exe.

Is that what you want? or are you looking for the FIRST Process
to load the dll into memory?

If the latter design is desired, the only way I see this happen
under Win32 is to create a shared memory or named kernel object
and use the idea of which first process created the shared memory
(or named kernel object) as the original loading process.

The named kernel object is probably the easiest way to do this.
You can then use the module name as named object. When the
DLL_ATTACH_PROCESS situation occurs, you first attempt to
see if the named object exist. If so, skip the creation.

You can also export a function called:

GetOriginalModuleFileName()

to retrieve the module name stored in the named kernel object.

That should work. But I hope I didn't go into something more
complex than what you are looking for. :-)


0 new messages