在qtp中引用外部dll的方法

上一篇 / 下一篇  2008-08-28 13:12:01 / 个人分类:QTP

Extern Object 用于调用外部DLL中的过程,与之相关的方法是Declare Method,这个方法的作用是声明外部DLL中的过程(或方法),以便让qtp脚本中使用。语法如下:

Extern.Declare(RetType,MethodName,LibName,Alias[,ArgType(s)])

如下的例子使用 Extern.Declare Extern.<declared method>方法改变“记事本”窗口的标题

声明FindWindow方法

Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString

声明SetWindowText方法

Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString

获得记事本窗口的句柄

hwnd = Extern.FindWindow("Notepad", "未定标题 - 记事本")

if hwnd = 0 then

MsgBox "Notepad window not found"

else

MsgBox hwnd

end if

改变记事本窗口的标题为“kuku”

res = Extern.SetWindowText(hwnd, "kuku")

注意:这个实验很多人不成功是由于记事本窗口没有打开,或者脚本中记事本窗口的标题写的不对(看着像可不行)。


TAG: QTP

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-07  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 5842
  • 日志数: 8
  • 建立时间: 2008-08-26
  • 更新时间: 2008-09-02

RSS订阅

Open Toolbar