QTP引用外部dll的3种方法

1、Active DLL
通过CreateObject
(class)创建:
dim ws
set ws = CreateObject("Wscript.shell")
ws.run "Notepad.exe"

GetObject([pathname] [, class])
参数
Pathname
可选项。字符串,包含待检索对象的文件的完整路径和名称。如果省略 pathname 则必须有 class。
Class
可选项。字符串,对象的类。
class 参数的语法格式为 appname.objectype,其中包括以下部分:
参数
appname
必选项。字符串,提供对象的应用程序名称。
objectype
必选项。字符串,要创建的对象的类型或类。

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set cpu =objwmiservice.execQuery("select * from win32_processor")
for each item in cpu
cpu2=cpu2&"CPU:" & item.Name
next
msgbox cpu2


2、Win API DLL
Extern.Declare
(RetType, MethodName, LibName, Alias [, ArgType(s)])
参数说明:
RetType: 方法返回值的类型。
MethodName:调用DLL文件中的某个方法的方法名。
LibName: DLL文件名。
Alias: 别名,当别名为空时,方法名和别名一样(此参数通常为空)。
ArgType(s): 传入的参数。

Extern.Declare micLong, "WinExec", "kernel32.dll", "WinExec", micString,micLong
Extern.WinExec "c\test.exe ", test


3、.Net API DLL
DotNetFactory.CreateInstance
(TypeName [,Assembly] [,args])
typename 其实就是命名空间+class名
assembly 其实就是程序集地址,可以本地路径,也可以是.net命名空间
args 其实就是class实例时构造函数的参数值

Set MyMsgBox = DotNetFactory.CreateInstance("System.Windows.Forms.MessageBox","System.Windows.Forms")
MyMsgBox.Show "Hello World ", "My Custom Message box"

Set MyMsgBox1 = DotNetFactory.CreateInstance("System.Windows.Forms.MessageBox","D:\defineDLL.dll","title")
MyMsgBox1.Show "Hello World ", "My Custom Message box"


PS:其中第1种和第3种都可以自定义dll来扩充,其中自定义第一种active dll后在使用前需要在系统中注册一下【regsvr32 dllName】
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值