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

Finding parent process of a DLL

0 views
Skip to first unread message

Steve McLellan

unread,
Mar 2, 2004, 10:19:39 AM3/2/04
to
Hi,

Probably an easy one if you know how, but I'm stumped...

I've got a function in a DLL and I need to be able to find out the
application path of the application that's called it. From my searches there
seems to be some stuff that allows you to list currently running processes
but this isn't quite what I need. Any help appreciated.

Steve


Carl Daniel [VC++ MVP]

unread,
Mar 2, 2004, 11:13:18 AM3/2/04
to

THCAR szName[MAX_PATH]
::GetModuleFileName(0,szName,MAX_PATH);

-cd


Steve McLellan

unread,
Mar 2, 2004, 11:17:19 AM3/2/04
to

That sounds like it'll do the trick, thanks :-)

What's classed as a 'module'? Aren't DLLs considered modules themselves?
From what I picked up from the documentation, it seemed like applications
are considered processes, and processes can have more than one module under
their command. The example I've got is a plug-in DLL running inside a host
application, and I need the filename of the application.

Thanks,

Steve


Carl Daniel [VC++ MVP]

unread,
Mar 2, 2004, 2:41:45 PM3/2/04
to

"Steve McLellan" <s...@fixerlabs.com.NOSPAM> wrote in message
news:%23K9mWHH...@TK2MSFTNGP09.phx.gbl...


DLLs, EXEs, Drivers (which are really DLLs) are Modules. The HMODULE for a
module is simply the base address of the module image cast to DWORD (e.g.
EXEs are typically based at 0x40000 so their HMODULE is 0x40000).

The documentation for GetModuleFileName is a bit misleading since it says
that passing NULL as the HMODULE will return the name of the "current
module". What it doesn't say is that the "current module" is in fact the
module from which the calling process was created - i.e. the EXE file.

-cd


William DePalo [MVP VC++]

unread,
Mar 2, 2004, 2:49:59 PM3/2/04
to
"Steve McLellan" <s...@fixerlabs.com.NOSPAM> wrote in message
news:%23K9mWHH...@TK2MSFTNGP09.phx.gbl...
> What's classed as a 'module'? Aren't DLLs considered modules themselves?

Yes, they are. But by passing zero for the module handle as Carl suggests,
you are asking the function to return the "main" module.

Regards,
Will


Steve McLellan

unread,
Mar 3, 2004, 6:37:49 AM3/3/04
to
OK, cheers both of you - that's a lot clearer than the documentation.

Thanks!

Steve

"William DePalo [MVP VC++]" <willd....@mvps.org> wrote in message
news:%23GEZG%23IAEH...@TK2MSFTNGP09.phx.gbl...

0 new messages