Yochai Timmer Yochai Timmer - 1 month ago 24
C++ Question

Get DLL path at runtime

I want to get a dll's directory (or file) path from within its code. (not the program's .exe file path)

I've tried a few methods I've found:

GetCurrentDir
- gets the current directory path.

GetModuleFileName
- gets the executable's path.

So how can i find out in which dll the code is in ?

I'm looking for something similar to C#'s
Assembly.GetExecutingAssembly

Answer
EXTERN_C IMAGE_DOS_HEADER __ImageBase;

....

WCHAR   DllPath[MAX_PATH] = {0};
GetModuleFileNameW((HINSTANCE)&__ImageBase, DllPath, _countof(DllPath));