如何在ActiveX内下载网站上的文件?

wxq 2000-02-15 09:21:00
我在网页内做了一个控件,想让用户在使用控件时去读取网站上的一个文件。请问,怎样编VC程序才行?网络名UNC是怎么用的?
...全文
179 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dengdun 2000-02-16
  • 打赏
  • 举报
回复
CInternetSession session(_T("test"), PRE_CONFIG_INTERNET_ACCESS);
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
try
{
CString szURL="http://www.test.com/test.dat"
CString strServerName;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;
AfxParseURL(szURL,dwServiceType,strServerName,strObject,nPort);
pServer = session.GetHttpConnection(strServerName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,strObject, NULL,1,NULL,NULL, INTERNET_FLAG_EXISTING_CONNECT and INTERNET_FLAG_NO_AUTO_REDIRECT);
pFile->SendRequest();
TCHAR szTemp[1024];
CFile tempFile;
tempFile.Open("C:\\temp\\temp.dat",CFile::modeCreate and CFile::modeWrite);
int nRead = pFile->Read(szTemp,1023);
while (nRead > 0)
{
szTemp[nRead] = '\0';
tempFile.Write(szTemp,nRead);
nRead = pFile->Read(szTemp, 1023);
}
tempFile.Close();
pFile->Close();
pServer->Close();
}
catch (CInternetException* pEx)
{
TCHAR szErr[1024];
pEx->GetErrorMessage(szErr, 1024);
AfxMessageBox(szErr);
pEx->Delete();
}
if (pFile != NULL)
delete pFile;
if (pServer != NULL)
delete pServer;
session.Close();
dengdun 2000-02-16
  • 打赏
  • 举报
回复
CInternetSession session(_T("test"), PRE_CONFIG_INTERNET_ACCESS);
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
try
{
CString szURL="http://www.test.com/test.dat"
CString strServerName;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;
AfxParseURL(szURL,dwServiceType,strServerName,strObject,nPort);
pServer = session.GetHttpConnection(strServerName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,
strObject, NULL, 1, NULL, NULL, INTERNET_FLAG_EXISTING_CONNECT and INTERNET_FLAG_NO_AUTO_REDIRECT);
pFile->SendRequest();
TCHAR szTemp[1024];
CFile tempFile;
tempFile.Open("C:\\temp\\temp.dat",CFile::modeCreate and CFile::modeWrite);
int nRead = pFile->Read(szTemp,1023);
while (nRead > 0)
{
szTemp[nRead] = '\0';
tempFile.Write(szTemp,nRead);
nRead = pFile->Read(szTemp, 1023);
}
tempFile.Close();
pFile->Close();
pServer->Close();
}
catch (CInternetException* pEx)
{
TCHAR szErr[1024];
pEx->GetErrorMessage(szErr, 1024);
AfxMessageBox(szErr);
pEx->Delete();
}
if (pFile != NULL)
delete pFile;
if (pServer != NULL)
delete pServer;
session.Close();
dengdun 2000-02-16
  • 打赏
  • 举报
回复
CInternetSession session(_T("test"), PRE_CONFIG_INTERNET_ACCESS);
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
try
{
CString strServerName;
CString strObject;
INTERNET_PORT nPort;
DWORD dwServiceType;
pServer = session.GetHttpConnection(strServerName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,
strObject, NULL, 1, NULL, NULL,
INTERNET_FLAG_EXISTING_CONNECT and INTERNET_FLAG_NO_AUTO_REDIRECT);
pFile->SendRequest();
TCHAR szTemp[1024];
CFile tempFile;
tempFile.Open("C:\\temp\\temp.dat",CFile::modeCreate and CFile::modeWrite);
int nRead = pFile->Read(szTemp,1023);
while (nRead > 0)
{
szTemp[nRead] = '\0';
tempFile.Write(szTemp,nRead);
nRead = pFile->Read(szTemp, 1023);
}
tempFile.Close();
pFile->Close();
pServer->Close();
}
catch (CInternetException* pEx)
{
TCHAR szErr[1024];
pEx->GetErrorMessage(szErr, 1024);
AfxMessageBox(szErr);
pEx->Delete();
}
if (pFile != NULL)
delete pFile;
if (pServer != NULL)
delete pServer;
session.Close();
wxq 2000-02-16
  • 打赏
  • 举报
回复
Dou:
Thank you! 若能详细一些更好,最好是代码.
netmare 2000-02-15
  • 打赏
  • 举报
回复
UNC明表示为形如\\主机名\...\共享资源名
如\\.\diskc\share表示本机上的一个共享资源share
DOU 2000-02-15
  • 打赏
  • 举报
回复
可以使用vc中的WinInet API,主要是使用几个类,如: CHttpConnection,CHttpFile,
CFtpConnection,CFtpFileFind,CHtmlStream...等等,具体请查阅MSDN,MSDN里有例子

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧