'C++ URLDownloadToFile to executable directory in CLR forum

I'm trying to figure out how I can fix two issues that I've been having with the URLDownloadToFile function in C++. The first is that when attempting to download the file in question, the download doesn't actually appear until the CLR C++ window is closed. The second is that as shown on the image below, the resulting file's file name and extension (Which is above the success window) is messed up (Although opening it normally shows that the file downloaded fine, with the name as the exception). If anyone has any suggestions on what I could do to fix these two issues, I'd greatly appreciate it.

What occurs when I attempt to run this code for downloading the file in question

For this logic, I'm using:

{
    char buffer[MAX_PATH];
    GetModuleFileNameA(NULL, buffer, MAX_PATH);
    std::string::size_type pos = std::string(buffer).find_last_of("\\/");

    return std::string(buffer).substr(0, pos);
}

void StartDownload()
{
    HRESULT downloadUpdate;
    LPCTSTR downloadUrl = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", File = "download.png";

    string currentDirectory = GetCurrentDirectory();
    LPTSTR currentDirectoryLPTSTR = new TCHAR[currentDirectory.size() + 1];

    std::string(currentDirectoryLPTSTR).append(File).c_str();

    downloadUpdate = URLDownloadToFile(0, downloadUrl, currentDirectoryLPTSTR, 0, 0);
    switch (downloadUpdate)
    {
    case S_OK:
        updateSuccess();
        break;
    case E_OUTOFMEMORY:
        updateOOMError();
        break;
    case INET_E_DOWNLOAD_FAILURE:
        updateError();
        break;
    default:
        updateErrorUnknown();
        break;
    }
}

[STAThread]
int main() {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    Application::Run(gcnew UpdaterGUIProject::UpdaterGUI()); 

    StartDownload();

    return 0;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source