Obtain the path of the running application

Source: Internet
Author: User

I summarized two methods from the Internet and analyzed them based on my experience. Two global methods:

1. getcurrentdirectory Method

Cstring getcurrworkingdir () </P> <p >{</P> <p> cstring strpath; <br/> getcurrentdirectory (max_path, strpath. getbuffer (max_path); <br/> // The current path returned by the function changes with the operation of the application, for example, when the application is running, the path to the directory where the application is located is obtained. when compiling and running a project, the real host is IDE, so the current directory is the directory where the project is located, not the debug or release directory. note this. When the application has operations such as "Open File", the path obtained by the function is "Open File" at the end of the operation, instead of the directory path where the application is running <br/> strpath. releasebuffer (); <br/> return strpath; <br/>}< br/>

2. getmodulefilename Method

Cstring cpropertysampleapp: getcurrworkingdir () <br/>{< br/> cstring strpath; <br/> tchar szfull [_ max_path]; <br/> tchar szdrive [_ max_drive]; <br/> tchar szdir [_ max_dir]; <br/>:: getmodulefilename (null, szfull, sizeof (szfull) /sizeof (tchar); <br/> _ tsplitpath (szfull, szdrive, szdir, null, null); <br/> _ tcscpy (szfull, szdrive ); <br/> _ tcscat (szfull, szdir); <br/> strpath = cstring (szfull); <br/> return strpath; <br/>}< br/>

This method can obtain the full path of the main module owned by the running process. The first parameter can be used to specify that the main module belongs to another process, if the default value is null, the full path of the executable module of the currently running process is obtained.

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.