Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,
I am using GetModuleFileName API in my program. It returns me the name of my executable. However, I see that under different environments, it give me output like

-- Win XP
output: test.exe
-- Win 7
output: TEST.EXE

not sure why the API gives me different outputs. Please help.
Posted

From GetModuleFileName()[^] in the MSDN:
Quote:
The string returned will use the same format that was specified when the module was loaded. Therefore, the path can be a long or short file name, and can use the prefix "\\?\".
So it should be like on your disk when double clicking the file in the Explorer and as typed when using the command shell to start the program.

Another cite:
Quote:
If a DLL is loaded in two processes, its file name in one process may differ in case from its file name in the other process.
While this applies to DLL's it indicates that the case it not always the same.

So you should accept the behaviour and optionally get the real name from the disk using FindFirstFile().
 
Share this answer
 
You already posted this question at http://www.codeproject.com/Messages/4619610/GetModuleFileName-and-case-sensitivity.aspx[^], and received some feedback. Please post in one forum only.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900