actually looking at the function reference, why do you need the loop at all? won't this be enough:

    vector<char> executablePath(MAX_PATH); 
    DWORD result = ::GetModuleFileNameA(nullptr, &executablePath[0], static_cast<DWORD>(executablePath.size())); 
    if(result==0){
         ofLogError("getCurrentExePath") << "failure of getting current executable path"; 
         return "";
    }else{
         executablePath.resize(result); 
         return string(executablePath.begin(), executablePath.begin() + result);
    }