VC++ gets the method for the current process to run the directory

  • 2020-04-02 02:56:15
  • OfStack

This article illustrates the VC++ to get the current process running directory method, to share for your reference. The specific implementation method is as follows:

This example is mainly obtained through the use of Windows API, the specific code is as follows:
 

CString GetAppPath() {
  CString strAppPath;  //Save the result
  TCHAR szModuleFileName[MAX_PATH]; //Full path name
  TCHAR drive[_MAX_DRIVE];  //Disk names, such as C disk, D disk
  TCHAR dir[_MAX_DIR]; //Directory < br / >   TCHAR fname[_MAX_FNAME];  //Process name
  TCHAR ext[_MAX_EXT]; //Suffix, usually exe or DLL
 
  if (NULL == GetModuleFileName(NULL, szModuleFileName, MAX_PATH)) //Gets the file path of the current process
  return FALSE;
 
  _tsplitpath_s( szModuleFileName, drive, dir, fname, ext );  //Split the path to get a disk, directory, file name, suffix
 
  strAppPath = drive;
  strAppPath += dir;
 
 
  return strAppPath;
}

 
The above code compiles and runs in VS2008. (requires MFC application or DLL)

Hope that this article described for everyone's VC++ programming help.


Related articles: