I wrote a dll that is dynamically called by a third party software exe. I need to get from inside the dll at runtime the full path to the dll. I've tried to follow this post:
Get DLL path at runtime
I wrote a proc inside my dll that refers to itself.
But it's not working for me: the path returned is the exe path, not the dll path.
What am i doing wrong?
here is the proc code (windows 7, visual studio 2008):
void stardust_checkCDM(){
// GET this DLL path
char dllPathName[256];
HMODULE hm = NULL;
char dllLocalFunc[] = "stardust_checkCDM";
GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPCSTR) &dllLocalFunc, &hm );
GetModuleFileNameA( hm, dllPathName, sizeof(dllPathName) );
printf( "GetModuleFileNameA: %s\n", dllPathName );
...
}
// dllPathName returns caller exe full path name,
// instead of dll full path name.