Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting the current executable name

Tags:

c++

windows

Firstly, I would like to say that I don't mean the full path, what
GetModuleFileName or argv[0] yield. Is there a smarter solution than dismissing everything before the last backslash?

like image 535
0x6B6F77616C74 Avatar asked May 13 '12 14:05

0x6B6F77616C74


1 Answers

First of all you want to get hold of the full path to the executable by calling GetModuleFileName passing NULL as the module handle. Then call PathFindFileName to pull out the file name component.

There is in fact a difference between GetModuleFileName and argv[0]. The latter is the name used to start the process. It could be missing the full path, but more importantly here, it could be missing the .exe extension. If you want to know the actual filename then you need to use GetModuleFileName.

like image 83
David Heffernan Avatar answered Oct 04 '22 17:10

David Heffernan