Created
November 28, 2022 08:34
-
-
Save nem0/7823bd516e6ea895793a5352c38848e8 to your computer and use it in GitHub Desktop.
Donwload file on windows without 3rd party
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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