How to get executable path from managed dll

I have a managed DLL (written in C ++ / CLI) that contains the class used by the C # executable. In the class constructor, I need to access the full path of the executable that references the DLL. In the application itself, which I know, I can use the Application object for this, but how to do it from a managed DLL?

+4
source share
2 answers
Assembly.GetCallingAssembly() 

or

 Assembly.GetExecutingAssembly() 

or

 Assembly.GetEntryAssembly() 

Depending on your needs.

Then use the Location property or CodeBase (I never remember which one).

+14
source

@leppie: Thanks - that was the pointer I needed.

For future reference in C ++ / CLI, this is a valid syntax that works:

 String^ appPathString = Assembly::GetEntryAssembly()->Location; 

GetExecutingAssembly() provided that the name of the DLL

GetCallingAssembly() returned something like System.Windows.Forms

GetEntryAssembly returned a full path similar to GetModulePath() under Win32.

+5
source

Source: https://habr.com/ru/post/1277070/


All Articles