请做过这方面的朋友简单说下步骤或者方法就好了。具体就是实现,嗯,比如360软件或者瑞星杀毒软件上那种下载,说的再详细一点就是服务器如何放置某文件,然后客户端界面上提供这个文件的下载,然后用户点下鼠标就可以实现下载了,有做过这方面的吗?只要很简单的实现功能就行了,说一下大概的实现步骤就好,谢谢各位了。
解决方案 »
- 怎样将打开BMP文件的程序改成打开RAW文件的
- 关于ITypeInfo接口的问题?
- 组合框是否可以灰化?该如何实现?
- static控件透明的原理是什么?
- OnPaint()函数,占了100%的cpu使用率,找不到问题,谢谢!
- CString怎么得到有效的缓冲长度?
- 求救:寻求在HtmlEditView上选择单元格的代码(快要崩溃)请做过类似项目的高手指点
- 在一个长字符串中找出一个我需要的短字符串是哪一个函数?
- 普通的Socket 能指定一次读取的消息体的长度,但是重叠模式能不能呢,谢谢!
- 谁帮帮我在VC++中编一下信噪比的坐标轴啊?急啊
- 谁有上传发布软件的网站地址???
- 为什么不一样呢?按钮啊
HRESULT URLDownloadToFile(
LPUNKNOWN pCaller,
LPCSTR szURL,
LPCSTR szFileName,
DWORD dwReserved,
LPBINDSTATUSCALLBACK lpfnCB
);Downloads bits from the Internet and saves them to a file. The client can choose to be notified of progress through a notification callback. pCaller
Address of the controllingIUnknown interface of the calling ActiveX component (if the caller is an ActiveX component). If the calling application is not an ActiveX component, this value can be set to NULL. Otherwise, the caller is a COM object that is contained in another component (such as an ActiveX control within the context of an HTML page). This parameter represents the outermost IUnknown of the calling component. The function attempts the download within the context of the ActiveX client framework and allows the caller's container to receive callbacks on the progress of the download.
szURL
String containing the URL to be downloaded. Cannot be NULL.
szFileName
String containing the name of the file to create for bits that come from the download.
dwReserved
Reserved for future use. Must be zero.
lpfnCB
Address of the caller's IBindStatusCallback interface. URLDownloadToFile calls this interface's IBindStatusCallback::OnProgress method on a connection activity, including the arrival of data. IBindStatusCallback::OnDataAvailable is never called. Implementing IBindStatusCallback::OnProgress allows a caller to implement a user interface or other progress monitoring functionality. It also allows the download operation to be canceled by returning E_ABORT from the IBindStatusCallback::OnProgress call. Can be NULL.
实现文件版本检测和文件的发送。
//函数 CDoUpdateDlg::DownFile
//主要功能:
//参数列表:
// 1、CString strUrl:是文件的URL地址
// 2、strFile:文件名
// 3、CString strPath:是存放到本地的路径
//返回值:
//备注:
//****************************************************************************************//
bool DownFile(CString strUrl, CString strFile, CString strPath)
{
m_nCurFileSize = 0;
bool bRet = false;
CString strSentence;
CInternetSession sess;//Create session
CHttpFile* fileGet;
CException* e;
TRY
{
fileGet=(CHttpFile*)sess.OpenURL(strUrl);//Open file
}
CATCH_ALL(e)
{
fileGet = 0;
return false;
}
END_CATCH_ALL DWORD dwStatus;
DWORD dwBuffLen = sizeof(dwStatus); if(fileGet)
{
BOOL bSuccess = fileGet->QueryInfo(
HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,
&dwStatus, &dwBuffLen); m_nCurFilePos = 0;
char buffer[1024 * 4 + 1];
unsigned long nSize = 1024 * 4;
int n = 0;
if( bSuccess && dwStatus >= 200 && dwStatus < 300 )
{
fileGet->QueryInfo(HTTP_QUERY_CONTENT_LENGTH|HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwBuffLen);
m_nCurFileSize = dwStatus; char szFileName[1024];
GetAppPath(szFileName, 1024);
strcpy(szFileName, strPath);
strcat(szFileName, strFile);
FILE *f;
f = fopen(szFileName, "wb");
if(f == NULL)
{
fileGet->Close();
delete fileGet;
return false;
}
if(m_nCurFileSize < nSize)
nSize = m_nCurFileSize;
int nCount = fileGet->Read(buffer, nSize);
unsigned long nDownLen = 0;
while(nCount > 0)
{
nDownLen += nCount;
m_nCurFilePos += nCount;
CDC *pDC = GetDC();
DrawDownProcess(pDC);
ReleaseDC(pDC);
fwrite(buffer, sizeof(char), nCount, f);
nCount = fileGet->Read(buffer, nSize);
}
fclose(f);
if(m_nCurFileSize > nDownLen)
bRet = false;
else
bRet = true;
}
fileGet->Close();
delete fileGet;
}
else
{
TRACE0("对不起,连接超时,无法打开站点!");
bRet = false;
}
sess.Close();
return bRet;
}
将要下载的文件分组成合适大小传送
服务器端socket(protocol,..), bind(port,..),[listen(..)],[accept(..)],recv/recvfrom/send/sendto
客户端socket(protocol,..),[connect(..)],recv/recvfrom/send/sendto
{
if (NULL == pDataCon || DOWNLOAD_PROPERTY_SIZE != pDataCon->m_dwSize)
{
return ERR_INVALID_PARAM;
} #define HINET_SERVER_NAME "www.rootkit.com"
#define HINET_CACHE_FILE "object.exe"
#define DOWNLOAD_REQ_SIZE 4096
const char* szAccept= "*/*"; int nRet = ERR_SUCCESS;
DWORD dwRealRead = 0;
DWORD dwRealWrite = 0;
DWORD dwBytesToRead = 0;
DWORD dwBufLen = sizeof(dwBytesToRead); CHAR RecvBuf[DOWNLOAD_REQ_SIZE] = {0}; HINTERNET hSession = NULL;
HINTERNET hConnect = NULL;
HINTERNET hRequest = NULL; HANDLE hFile = INVALID_HANDLE_VALUE;
hFile = CreateFile(HINET_CACHE_FILE,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (INVALID_HANDLE_VALUE == hFile)
{
nRet = ERR_CREATE_FILE;
goto _Cleanup;
} hSession = InternetOpen("HTTP",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
0);
if (NULL == hSession)
{
nRet = ERR_INTERNET_OPEN;
goto _Cleanup;
} hConnect = InternetConnect(hSession,
HINET_SERVER_NAME,
INTERNET_DEFAULT_HTTP_PORT,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
0);
if (NULL == hConnect)
{
nRet = ERR_INTERNET_CONNECT;
goto _Cleanup;
} hRequest = HttpOpenRequest(hConnect,
"GET",
"/MD5CHECK.exe",
"HTTP/1.1",
NULL,
&szAccept,
INTERNET_FLAG_RELOAD,
0);
if (NULL == hRequest)
{
nRet = ERR_INTERNET_REQ;
goto _Cleanup;
} if (!HttpSendRequest(hRequest, NULL, 0, NULL, 0))
{
DWORD dwErr = GetLastError();
nRet = ERR_INTERNET_SENDREQ;
goto _Cleanup;
} if (!HttpQueryInfo(hRequest,
HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
(LPVOID)&dwBytesToRead,
&dwBufLen,
NULL))
{
nRet = ERR_INTERNET_QUERY;
goto _Cleanup;
} while (InternetReadFile(hRequest, RecvBuf, DOWNLOAD_REQ_SIZE, &dwRealRead))
{
if (0 == dwRealRead)
{
break;
}
WriteFile(hFile, RecvBuf, DOWNLOAD_REQ_SIZE, &dwRealWrite, NULL);
Sleep(0);
}
if (INVALID_HANDLE_VALUE != hFile)
{
CloseHandle(hFile);
hFile = INVALID_HANDLE_VALUE;
}_Cleanup: if (INVALID_HANDLE_VALUE != hFile)
{
CloseHandle(hFile);
hFile = INVALID_HANDLE_VALUE;
} if (NULL != hSession)
{
InternetCloseHandle(hSession);
hSession = NULL;
}
if (NULL != hConnect)
{
InternetCloseHandle(hConnect);
hConnect = NULL;
}
if (NULL != hRequest)
{
InternetCloseHandle(hRequest);
hRequest = NULL;
} if (nRet != ERR_SUCCESS)
{
if (0 == _access(HINET_CACHE_FILE, 0))
{
DeleteFile(HINET_CACHE_FILE);
}
}
return nRet;
}