image.png
image.png
22
参数:
pCaller:Pointer to the controlling IUnknown interface of the calling Microsoft ActiveX component (if the caller is an ActiveX component).
//该参数为 ActiveX 控件的接口指针,如果当前程序不是 ActiveX 控件则写 NULL 就可以了。
szURL
Pointer to a string value containing the URL to be downloaded. Cannot be set to NULL.
//该参数为要下载的 url 地址,不能为空。
szFileName
Pointer to a string value containing the name of the file to create for bits that come from the download.
//下载文件后,保存的文件名字,包含文件的具体路径信息。
dwReserved
Reserved. Must be set to 0.
//保留字段,必需为0。
lpfnCB
Pointer to 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.
//下载进度状态回调接口的指针。如果要实时监视下载文件的状态那么就要用到这个参数了。
返回值:
S_OK : 成功下载;
E_OUTOFMEMORY:缓冲区长度不够,或者没有足够的内存来完成下载的操作;
INET_E_DOWNLOAD_FAILURE:指定的资源或者回调接口有问题。
image.png
image.png
image.png
111
image.png
image.png
image.png
111
image.png
image.png image.png
打开了
image.png
打开记事本:
image.png image.png image.png
===============================================================
=======================================代码部分=================
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "Stack.h"
#include <tchar.h>
using namespace std;
#pragma comment(lib,"Urlmon.lib")
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
HRESULT hret = URLDownloadToFile(NULL, _T("https://s.cctry.com/images/eagle2.png "), _T("D:\\123.png"), 0, NULL);
if (hret == S_OK )
{
MessageBox(NULL,_T("下载成功!"),_T("Tip"),MB_OK);
}
else
{
MessageBox(NULL, _T("下载失败!"), _T("Tip"), MB_OK);
}
return 0;
}
第二个api函数,我测试了,很成功!
image.png
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <tchar.h>
#include <URLmon.h>
using namespace std;
#pragma comment(lib,"Urlmon.lib")
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
//HRESULT hret = URLDownloadToFile(NULL, _T("https://avatar.cctry.com/uc_server/data/avatar/000/00/00/51_avatar_middle.jpg"), _T("D:\\御龙在天喊话\\123.jpg"),0, NULL);
/*if (hret == S_OK)
{
MessageBox(NULL, _T("下载成功!"), _T("Tip"), MB_OK);
}
else
{
MessageBox(NULL, _T("下载失败123!"), _T("Tip"), MB_OK);
}*/
//第二个函数的使用
SHELLEXECUTEINFO ShellInfo = {0};
ShellInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShellInfo.lpVerb = _T("open");
ShellInfo.lpFile = _T("notepad.exe");
ShellInfo.nShow = SW_SHOW;
BOOL bRet = ShellExecuteEx(&ShellInfo);
return 0;
}
网友评论