Question : Why does GetModuleFileName return long names sometimes, and mangled names sometimes (WinNT)?

I want to use GetModuleFileName to retrieve the name of the active DLL (or EXE), but for some DLL's (e.g. ATL) I get mangled names and other I get the full long name.

OK, I know how to find out the real, long name in the end, but I would like to know why GetModuleFileName behaves differently, and in what situations.

Thanks

Answer : Why does GetModuleFileName return long names sometimes, and mangled names sometimes (WinNT)?

Without seeing your code I really dont know whats wrong I have never experienced anything like you say - so its probably the fact that your missing something

What are you trying to retreive, the calling process ?? If so the following will return the full path of the program which called your DLL

// Check who's loading us.
TCHAR pszLoader[MAX_PATH];
GetModuleFileName(NULL, pszLoader, MAX_PATH);

Or if you want your own path - obtain the handle of the DLL - substitute it for the first parameter - which is NULL in the above example

HMODULE hMod = GetModuleHandle("Your.DLL"); // address of module name to return handle for
char lpBuffer[MAX_PATH];
        
/* Get the working directory of the program (module file name)*/
::GetModuleFileName(hMod,      // handle to module to find filename for
                lpBuffer,      // pointer to buffer for module path
                MAX_PATH);      // size of buffer, in characters


For an EXE file :
HMODULE hMod = GetModuleHandle(NULL); // address of module name to return handle for
char lpBuffer[MAX_PATH];
        
/* Get the working directory of the program (module file name)*/
::GetModuleFileName(hMod,      // handle to module to find filename for
                lpBuffer,      // pointer to buffer for module path
                MAX_PATH);      // size of buffer, in characters

Let me know if there is anything else - without seeing your code it may be a little difficult

DarrinE
Random Solutions  
 
programming4us programming4us