Skip to content

Instantly share code, notes, and snippets.

@icebreaker
Forked from nem0/download.cpp
Created November 28, 2022 08:47
Show Gist options
  • Save icebreaker/358d4f52c40d6da8e5eec84c13dd673d to your computer and use it in GitHub Desktop.
Save icebreaker/358d4f52c40d6da8e5eec84c13dd673d to your computer and use it in GitHub Desktop.
Donwload file on windows without 3rd party
#include <urlmon.h>
#pragma comment(lib, "urlmon.lib")
bool download(const char* url, OutputMemoryStream& blob) {
IStream* stream = nullptr;
if (S_OK != URLOpenBlockingStream(nullptr, url, &stream, 0, nullptr)) {
return false;
}
char buffer[4096];
ULONG read = 0;
HRESULT hr;
do {
DWORD bytesRead = 0;
hr = stream->Read(buffer, sizeof(buffer), &bytesRead);
if (bytesRead > 0)
{
blob.write(buffer, bytesRead);
}
} while (SUCCEEDED(hr) && hr != S_FALSE);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment