• Window mobile 实现HTTP小文件下载


    BOOL HttpDown(void)   
    {
    	HINTERNET hinternet = InternetOpen(_T("CartoType"),INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
    	if (NULL == hinternet)
    	{
    		MessageBox(L"打开网络不成功",L"错误",MB_OKCANCEL);
    		InternetCloseHandle(hinternet);
    		return FALSE;
    	}
    	HINTERNET hfile = InternetOpenUrl(hinternet,(LPCTSTR)szURL,NULL,0,0,1);
    	if (NULL == hfile)
    	{
    		MessageBox(L"打开网络地址不成功",L"错误",MB_OKCANCEL);
    		InternetCloseHandle(hfile);
    		InternetCloseHandle(hinternet);
    		return FALSE;
    	}
    	char Buffer[32] = {0};
    	DWORD BufLen = sizeof(Buffer);
    	DWORD WIndex = 0;
    	DWORD dwFileSize = 0;
    	HttpQueryInfo(hfile,HTTP_QUERY_CONTENT_LENGTH   , Buffer, &BufLen, &WIndex);
    	dwFileSize=(DWORD)_wtoi((wchar_t*)Buffer);
    	CFile myFile;
    	CFileException fileException;
    	CString currentPath,fileName;
    	GetCurrentDirectory(currentPath);
    	if ( !myFile.Open (currentPath+fileName, CFile::modeCreate | CFile::modeReadWrite,
    		&fileException ) )
    	{
    		MessageBox(L"创建文件不成功",L"错误",MB_OKCANCEL);
    		return FALSE;
    	}
    	if (dwFileSize==0)
    		dwFileSize=10000000;//设置个最大值
    	DWORD tmp2=dwFileSize/100;
    	DWORD currentFileSize=0;
    	CString str;
    	str.Format(_T("已下载%d%%"),0);
    	DWORD dwSize;
    	VOID * szTemp[25];
    	do
    	{
    		if (!InternetReadFile (hfile, szTemp, 50,  &dwSize) )
    		{
    			myFile.Close();
    			return FALSE;
    		}
    		if (!dwSize)
    			break;  // Condition of dwSize=0 indicate EOF. Stop.
    		else
    		{
    			myFile.Write(szTemp,dwSize);
    			currentFileSize+=dwSize;
    		}
    
    		if ((currentFileSize/50)%(tmp2/50)==0)
    		{
    			lb.DeleteString(lb.GetCount()-1);
    			str.Format(_T("已下载%d%%"),currentFileSize/tmp2);
    		}
    	}   // do
    	while (TRUE);
    	myFile.Close();
    	InternetCloseHandle(hfile);
    	InternetCloseHandle(hinternet);  
    	return TRUE;
    }
  • 相关阅读:
    第07节-开源蓝牙协议BTStack框架代码阅读(上)
    第06节-开源蓝牙协议BTStack框架分析
    第05节-BLE协议物理层(PHY)
    第04节-BLE协议抓包演示
    第03节-BLE协议各层数据格式概述
    【重点声明】此系列仅用于工作和学习,禁止用于非法攻击。一切遵守《网络安全法》
    海外信息安全资源
    从浏览器攻击思考入门的问题。
    攻击载荷免杀技术
    聊聊NTLM认证协议
  • 原文地址:https://www.cnblogs.com/lartely/p/1995162.html
Copyright © 2020-2023  润新知