Skip to content

Instantly share code, notes, and snippets.

@nem0
Created November 28, 2022 08:34
Show Gist options
  • Save nem0/7823bd516e6ea895793a5352c38848e8 to your computer and use it in GitHub Desktop.
Save nem0/7823bd516e6ea895793a5352c38848e8 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