VB.NET编程调用讯雷下载文件


  首先确保电脑已经安装讯雷, 打开VS.NET 点击菜单: 名目->增加 引用->COM->增加对ThunderAgent 1.0 Type Library的 引用

  1. 缔造讯雷调用对象

Private ThunderEng As New ThunderAGENTLib.Agent' 缔造讯雷调用对象

ThunderEng.AddTask("下载地址", "另存文件名", " 保留目录"," 使命 诠释"," 引用地址","开始模式", "只从原始地址下载","从原始地址下载线程数") '增加下载 使命

ThunderEng.CommitTasks()'提交下载 使命

  2. 使用讯雷调用对象 查问下载 使命信息

sFileSize = ThunderEng.GetTaskInfo(txtURL.Text, "FileSize")'猎取下载文件大小

sDownedSize = ThunderEng.GetTaskInfo(txtURL.Text, "CompletedSize")'猎取已 实现大小

sFileName = ThunderEng.GetTaskInfo(txtURL.Text, "FileName")'猎取文件名

  迅雷平台接口函数定义

   获得信息

  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 猎取失败