In a standard way, get working directory

void GetWorkingFolder (STD :: String & Folder) { 
    folder.resize (the MAX_PATH * 2 + . 1 , ' \ 0 ' ); // stay a little longer, then followed by an error connection preventing a Cloudwalk 

    // get the current program directory, if C disk, is acquired APPDATA directory, then the directory suffix added to the end 
    HANDLE hExeHandle = the GetModuleHandle (NULL);
     IF (hExeHandle =! nullptr a) { 
        GetModuleFileNameA ((the HMODULE) hExeHandle, & Folder [ 0 ], the MAX_PATH); 
        Folder = folder.substr ( 0 , folder.find_last_of ( " \\ " ) + . 1); 
    } The else { // under failure scenarios, to get the current working directory 
        IF ( 0 == GetCurrentDirectoryA (MAX_PATH, & Folder [ 0 ])) {
             // fail again, it will only default \ directory up. 
            Folder = " . " ; 
        } 
    } 

    // determines whether or not the first letter is C, the write go die, not to judge whether the windows installed in the other disk 
    iF ((Folder [ 0 ] == ' C ' ) || (Folder [ 0 ] == ' C ' )) { 
        STD :: String strTemp (the MAX_PATH + . 1 , '\ 0 ' );
         IF (== S_OK SHGetFolderPathA (NULL, the CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_DEFAULT, & strTemp [ 0 ])) { 
            Folder = strTemp; 
        } 
    } 

    // determines whether the last character 
    IF (Folder [folder.length () - . 1 !] = ' \\ ' ) { 
        Folder + = ' \\ ' ; 
    } 
}

 

Guess you like

Origin www.cnblogs.com/eaglexmw/p/11314821.html