Getting path of .exe from a dll

  • Thread starter Thread starter MarkMurphy
  • Start date Start date
M

MarkMurphy

Within a class that is implented in a called DLL is it possible to get
the path of the executable that is currently making use of that DLL?
This call returns the path of the dll:

Assembly.GetExecutingAssembly().GetName().CodeBase;

Mark
 
If you are inside a DLL method that you know was called by that EXE
directly, you can try Assembly.GetCallingAssembly()
Otherwise you will need to P/Invoke GetModuleFileName

[DllImport("coredll")]
extern static int GetModuleFileName( IntPtr hModule, StringBuilder
lpFilename, int nSize);

string GetCurrentProcessName()
{
int MaxPath = 256;
StringBuilder sb = new StringBuilder(MaxPath);
GetModuleFileName(IntPtr.Zero, sb, MaxSize);
return sb.ToString();
}
 
Back
Top