VC + + Get executable file current directory

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.