最近在研究乱七八遭的东西,想到这个点子,用VB。NET实现了,调用了讯雷的接口
首先确保电脑已经安装讯雷,打开VS.NET 点击
菜单:项目->添加引用->COM->添加对ThunderAgent 1.0 Type Library的引用
1.创建讯雷调用对象
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2.使用讯雷调用对象查询下载任务信息
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
二、迅雷平台接口函数定义
获得信息
1. BSTR GetInfo(BSTR pInfoName)
功能:获得迅雷或平台相关信息
参数:
参数名 | 含义 |
pInfoName | 信息名称,有如下4种 。“ThunderExists”:迅雷是否存在 。“ThunderRunning”:迅雷是否运行 。“ThunderVersion”:迅雷版本号 。“PlatformVersion”:平台版本号 |
返回值:
返回值是字符串与参数pInfoName有对应关系
参数 | 返回值 |
“ThunderExists” | “true”存在,“false”不存在 |
“ThunderRunning” | “true” 运行中, “false”未运行 |
“ThunderVersion” | 迅雷版本号 “x.x.x.x” |
“PlatformVersion” | 平台版本号 “x.x.x.x” |
2. HRESULT GetInfoStruct(INT pInfo)
功能:获取迅雷或平台相关全部信息
参数:
参数名 | 含义 |
pInfo | 其实是THUNDER_INFO类型的结构指针,调用前把它转换为INT类型;调用后结构中将填充平台信息,定义如下: typedef struct _THUNDER_INFO { BOOL bThunderExists; BOOL bThunderRunning; CHAR szThunderVersion[32]; CHAR szPlatformVersion[32]; } THUNDER_INFO; 函数调用后,结构中将填充相应的信息。 |
返回值:
0 | 获取成功 |
非0 | 获取失败 |
任务操作
3. 加入任务
HRESULT AddTask
(BSTR pURL,
BSTR pFileName = "",
BSTR pPath = "",
BSTR pComments = "",
BSTR pReferURL = "",
INT nStartMode = -1,
INT nOnlyFromOrigin = 0,
INT nOriginThreadCount = -1);
功能:
往平台加入下载任务信息,此时尚未体现到迅雷中
参数:
参数名 | 含义 |
pURL | 目标URL,必须参数 |
pFileName | 另存名称,默认为空,表示由迅雷处理,可选参数 |
pPath | 存储目录,默认为空,表示由迅雷处理,可选参数 |
pComments | 下载注释,默认为空,可选参数 |
pReferURL | 引用页URL,默认为空,可选参数 |
nStartMode | 开始模式,0手工开始,1立即开始,默认为-1,表示由迅雷处理,可选参数 |
nOnlyFromOrigin | 是否只从原始URL下载,1只从原始URL下载,0多资源下载,默认为0,可选参数 |
nOriginThreadCount | 原始地址下载线程数,范围1-10,默认为-1,表示由迅雷处理,可选参数 |
4. 开始任务
HRESULT CommitTaskss()
功能:
把AddTask所加入的下载任务信息真正提交到迅雷中进行下载,并从平台中删除
注意:如果AddTask添加的任务没有被提交没有被取消(调用CancelTasks),则Agent对象析构时会阻塞,所以调用者不应该残留一些没有被提交或者取消的任务,以避免脚本执行者停止响应。
5. 取消任务
HRESULT CancelTasks()
功能:
取消平台中所有由AddTask所加入的下载任务信息
6. 查询任务信息
BSTR GetTaskInfo(BSTR pURL,BSTR pInfoName);
参数:
参数名 | 含义 |
pURL | 所要查询的下载URL信息 |
pInfoName | 状态名称,有如下几种 。“Exists”:pURL是否在迅雷的任务列表 。“Path”:存储目录 。“FileName”:文件名称 。“FileSize”:文件大小 。“CompletedSize”:已下载大小 。“Percent”:下载进度 。“Status”:任务状态 |
返回值:
返回值是字符串与参数pInfoName有对应关系
参数 | 返回值 |
“Exists” | ”true”存在,”false”不存在 |
“Path” | 存储目录,最后带反斜线\,例:C:\TDDownload\ |
“FileName” | 文件名称 |
“FileSize” | 文件大小,以字节为单位,0表示大小未知 |
“CompletedSize” | 已下载大小,以字节为单位 |
“Percent” | 下载进度,带1位小数,例:70.0 |
“Status” | 任务状态,有以下6种状态 。“running”: 运行状态 。“stopped”: 停止状态 。“failed”: 失败状态 。“success”: 成功状态 。“creatingfile”:正在创建数据文件 。“connecting”: 正在连接 |
7. GetTaskInfoStruct(INT pTaskInfo)
功能:查询一个任务的所有信息
参数名 | 含义 |
pTaskInfo | 其实是THUNDER_TASKINFO类型的结构指针,调用前把它转换为INT类型;调用后结构中将填充平台信息,定义如下: typedef struct _THUNDER_TASKINFO { CHAR szURL[1024]; // 任务URL,预先填充 BOOL bTaskExists; // 任务是否存在,TRUE为存在 CHAR szPath[256]; // 下载的本地保存路径 CHAR szFileName[256]; // 本地文件名 ULONGLONG nFileSize; // 文件大小 ULONGLONG nCompletedSize; // 已完成的大小 CHAR szPercent[16]; // 完成的百分数,用 “56.8”的格式 CHAR szStatus[16]; // 当前状态,定义同GetTaskInfo函数 } THUNDER_TASKINFO; 调用者先填充结构中的szURL成员,来指定需要查询的任务的URL,然后等函数返回后就可以从其他成员中取得该任务的信息。 |
本例所有代码
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
源程序下载:点击下载代码
Power by Bention(翁培铖) http://www.bention.com