Finding parent process of a DLL

  • Thread starter Thread starter Steve McLellan
  • Start date Start date
S

Steve McLellan

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
 
Steve said:
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.

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

-cd
 
Steve said:
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.

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

-cd

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
 
Steve McLellan said:
Steve said:
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.

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

-cd

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.


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
 
Steve McLellan said:
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
 
OK, cheers both of you - that's a lot clearer than the documentation.

Thanks!

Steve
 
Back
Top