views:

35

answers:

3

Hello community,

I am building a DLL that is used by Office. When Office runs with it, I would like to identify where it is located. Is that possible?

ex. of code within the DLL when it is run within Office:

// should return C:\tmp\officeaddin.dll, 
// currently C:\Program Files\Microsoft Office\Office 12
MessageBox.Show(Application.StartupPath)   
+2  A: 

The following should work even if running inside of Office:

http://stackoverflow.com/questions/864484/getting-the-path-of-the-current-assembly

(It basically boils down to Assembly.GetExecutingAssembly().Location, but see the link above for more detailed information.)

Heinzi
beautiful thanks
m_oLogin
A: 

When the DLL loads, It calls DllMain with the instance handle. If you implement this function, you can then record the instance handle of the DLL. From this, you can then call GetModuleFileName.

In .NET this is taken care of for you. See this question and selected answer for details.

mdma
+2  A: 

If it is a .NET library, you should use Assembly.GetExecutingAssembly().Location. Application.StartupPath shows the path to the main app.

wRAR
beautiful thanks
m_oLogin