QTP/UFT引用外部dll的3种方法
2017-01-07 20:19
351 查看
QTP引用外部dll的3种方法 :Active DLL, Win API DLL, .Net API DLL
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】
相关文章推荐
- QTP引用外部dll的3种方法
- QTP引用外部dll的3种方法
- Python:字符串中引用外部变量的3种方法
- 解决使用VS2010时,引用外部dll时提示,无法嵌入互操作类型“……”,请改用适用的接口的解决方法
- 将引用的外部dll打包到程序中的方法
- QTP访问外部dll的三种方法
- QTP访问外部dll的三种方法
- 加载启动目录以外的DLL(Assembley)的3种方法
- 应用MasterPage的页面引用外部CSS文件的方法
- asp.net web service引用外部DLL中枚举的问题
- 在.NET中运行外部程序的3种方法
- 在powerbuilder中调用外部DLL中含有CHAR* *类型参数时的解决方法
- truncate报ORA-02266错“唯一/主键被启用的外部关键字引用”解决方法
- 引用Microsoft.Office.Interop.Excel.dll操作Excel常用方法
- 加载启动目录以外的DLL(Assembley)的3种方法
- 内部方法引用外部方法的参数
- 引用第三方库lib/dll出现的无法解析的外部符号问题
- 的引用(请使用 TLBIMP 实用工具来引用 COM DLL): 提供程序 DLL 未能正确初始化。----------解决方法
- 调试Web页面时,如果页面引用了外部JS代码,会被IE缓存的解决方法
- 应用MasterPage的页面引用外部CSS文件的方法