Click to See Complete Forum and Search --> : How do I find my DLL's location?


The_Diamond_Z
January 21st, 2004, 10:50 AM
I'm writing a C++ class that will sit inside one or more non MFC, non ATL COM dll's.

I have requirement to read a file from the same location as the DLL (which will be hosted in the client's process but which is not likely to be in the same directory) but I don't have any ideas on how to find out that location.

I thought about hitting the registry via th CLSID but my boss objects to that.

What I really want is the path the client process's LoadLibrary used to load the dll.

Any ideas?

Andreas Masur
January 21st, 2004, 11:00 AM
Well...'LoadLibrary()' returns the handle to the dll module which in turn can be used with 'GetModuleFileName()'...

For further information take a look at the following FAQ (http://www.codeguru.com/forum/showthread.php?s=&threadid=231171)...it will get the application path. Instead of passing '0' you need to pass the returned module handle as the first argument...

HMODULE hDll = LoadLibary(...);

GetModuleFileName(hDll, ...);

The_Diamond_Z
January 21st, 2004, 11:05 AM
Geez....that was quick and a perfect answer. Thanks!

Andreas Masur
January 21st, 2004, 04:51 PM
No problem...you are welcome...