zoukankan      html  css  js  c++  java
  • 用InternetOpen()的下载者

    #include<windows.h>
    #include<wininet.h>
    #include<iostream.h>
    #pragma comment(lib,"wininet.lib")
    void main()
    {
    DWORD byteread=0;
    char buffer[100];
    memset(buffer,0,100);
    HINTERNET internetopen;
    internetopen=InternetOpen("Testing",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
    if (internetopen==NULL){
       cout<<"Internet open failed!"<<endl;
    return;}
    HINTERNET internetopenurl;
    internetopenurl=InternetOpenUrl(internetopen,"http://www.saishuo.com/s.exe",NULL,0,INTERNET_FLAG_RELOAD,0);
         if (internetopenurl==NULL){
       cout<<"Internet open url failed!"<<endl;
       goto there;}
    
    BOOL hwrite;
    DWORD written;
    HANDLE createfile;
    createfile=CreateFile("c:\\sss.exe",GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
    if (createfile==INVALID_HANDLE_VALUE){
       cout<<"Create File failed!"<<endl;
    goto next;}
    BOOL internetreadfile;
    while(1){
    internetreadfile=InternetReadFile(internetopenurl,buffer,sizeof(buffer),&byteread);
    if(byteread==0)
       break;
    hwrite=WriteFile(createfile,buffer,sizeof(buffer),&written,NULL);
    if (hwrite==0){
       cout<<"Write to file failed!"<<endl;
    goto here;}
    }
    cout<<"Finished downloading!"<<endl;
    
    here:
    CloseHandle(createfile);
    next: 
    InternetCloseHandle(internetopenurl);
    there:
    InternetCloseHandle(internetopen);
    
    
  • 相关阅读:
    Flask_自定义参数类型(自定义转换器)
    数据结构与算法(排序)
    数据结构与算法(查找)
    Vue_fetch和axios数据请求
    Vue_修饰符
    Vue_列表过滤应用
    Vue_生命周期函数
    Vue_watch()方法,检测数据的改变
    Django_redis_缓存
    防火墙相关
  • 原文地址:https://www.cnblogs.com/zdxster/p/1945892.html
Copyright © 2011-2022 走看看