How to get the application executable name in WindowsC++/CLI?
Ferruccio's answer is good. Here's some example code:
TCHAR exepath[MAX_PATH+1];
if(0 == GetModuleFileName(0, exepath, MAX_PATH+1))
MessageBox(_T("Error!"));
MessageBox(exepath, _T("My executable name"));
Call GetModuleFileName() using 0 as a module handle.
Note: you can also use the argv[0]
parameter to main or call GetCommandLine()
if there is no main. However, keep in mind that these methods will not necessarily give you the complete path to the executable file. They will give back the same string of characters that was used to start the program. Calling GetModuleFileName()
, instead, will always give you a complete path and file name.