Char // MAX_PATH is a macro defined by Win32 that represents the maximum path allowed by Windows 255; GetCurrentDirectory (MAX_PATH, Lpszcurrentpath);
GetCurrentDirectory can get the directory that the program is currently running, not the current executable. I read other people's blogs on the internet, often see someone write this function can get the current executable file directory, think really mislead others ah. Of course, the name of this function is also very confusing.
Getting the current executable is another function: GetModuleFileName;
char Modulefilename[_max_path]; GetModuleFileName (NULL, Modulefilename, _max_path); char Exepath[_max_dir]; // current folder char Extname[_max_ext]; // file suffix char Exefname[_max_fname]; // file name char Exediver[_max_drive]; // file drives, such as C: _splitpath (Modulefilename, Exediver, ExePath, Exefname, extname);
_splitpath绝对是个好东西,在我不知道这个函数之前,居然手动把GetModuleFileName得到的文件路径名分解开来,想想真是伤心啊。
VC + + Get executable file current directory