Use Windows API to download files from the Internet

Source: Internet
Author: User

Author: crashsky QQ: 36460382

What we see on vckbase is the use of MFCCodeI wrote an API. This Code does not need to use MFC.

 

// First add the required header file

# Include <stdio. h>
# Include <tchar. h>
# Include <windows. h>
# Include <wininet. h>

// Add the Connection Library
# Pragma comment (Lib, "wininet. lib ")

Int main (INT argc, char * argv [])
{
Printf ("Hello world! ");
Byte Buf [1024];
Tchar path [max_path];
DWORD num;
 

// Open
Hinternet hinet = internetopen (_ text ("Microsoft Internet Explorer"), internet_open_type_preconfig, null, null, internet_invalid_port_number );
 
Gettemppath (max_path, PATH );
Strcat (path, "/t.zip ");

// Obtain the file handle
Hinternet hurl = internetopenurl (hinet, _ text ("http://file2.mydrivers.com/display/nvidia_forceware7645.zip"), null, 0, internet_flag_need_file, null );
 
File * I = fopen (path, "WB ");

// Download the object content from the Internet
While (true = internetreadfile (hurl, Buf, 1024, & num) & num> 0)
{
Fwrite (BUF, 1, num, I );
}
Fclose (I );

// Use the file handle and close the connection
Internetclosehandle (hurl );
 
Internetclosehandle (hinet );
 

Return 0;
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.