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
You can use the
GetModuleHandleExfunction and get the handle to a static function in your DLL. You’ll find more information here.After that you can use
GetModuleFileNameto get the path from the handle you just obtained. More information on that call is here.A complete example: