Skip to content

Instantly share code, notes, and snippets.

@fortheday
Created January 23, 2018 03:16
Show Gist options
  • Save fortheday/faf7864214a637ca315502272d506946 to your computer and use it in GitHub Desktop.
Save fortheday/faf7864214a637ca315502272d506946 to your computer and use it in GitHub Desktop.
// (WindowsInternet + VCL + MP_LIB 사용)
//---------------------------------------------------------------------------
#include <vcl.h>
#include <wininet.h>
#include <stdio.h>
#include "mp_File.h"
#include "MainForm.h"
#pragma comment (lib, "wininet.lib")
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
HINTERNET hInternet;
HINTERNET hInternetOpenUrl;
DWORD dwContext,
dwFileSize;
#define MAX_BUF_SIZE 1213952
static char buf[MAX_BUF_SIZE];
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
hInternet = InternetOpen("mp_wget", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
dwContext = 0;
hInternetOpenUrl = InternetOpenUrl(hInternet, "http://xyz2.com/gackt.jpg"; , NULL, 0, // headers, header-size,
INTERNET_FLAG_RAW_DATA, dwContext);
int nError = GetLastError();
if (InternetReadFile(hInternetOpenUrl, buf, MAX_BUF_SIZE, &dwFileSize))
{
HANDLE hFile = MPFILE::Open("gackt.jpg", MPFILE::owNewWriteRead);
MPFILE::Write(hFile, buf, dwFileSize);
MPFILE::SetEOF(hFile);
CloseHandle(hFile);
}
InternetCloseHandle(hInternetOpenUrl);
InternetCloseHandle(hInternet);
}
//---------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment