您的位置:首页 > 编程语言 > C语言/C++

Loadruuner C语言脚本--如何引用DLL文件

2015-12-11 15:55 330 查看
Loadrunner录制完成HTTP/HTML的C语言脚本后,通常在调脚本的过程中设置一些关联和参数脚本即可调通。而使用到DLL(Dynamic Link Library)文件,即动态链接库文件的场景其实比较少。因为dll文件与脚本一样保存在本地,属于一种本地调用了。一般使用的场景是涉及到一些参数,可能项目中的开发有自己的dll库,需要通过项目自己在dll文件处理之后,才能在脚本中使用。下面介绍一下Loadruuner中如何引用DLL文件。

1.DLL文件简介

以下为百度百科的解释:

DLL(Dynamic Link Library)文件为动态链接库文件,又称“应用程序拓展”,是软件文件类型。在Windows中,许多应用程序并不是一个完整的可执行文件,它们被分割成一些相对独立的动态链接库,即DLL文件,放置于系统中。当我们执行某一个程序时,相应的DLL文件就会被调用。一个应用程序可使用多个DLL文件,一个DLL文件也可能被不同的应用程序使用,这样的DLL文件被称为共享DLL文件。

相关链接:

DLL文件--百度百科

2. Loadrunner相关函数

//C Language
int lr_load_dll( const char *library_name );


详细解释如下,可以参考Loadrunner自带的帮助文档HP LoadRunner Online Function Reference

library_name
The name of a DLL (Windows) or shared object (UNIX).
The lr_load_dll function loads a DLL (Windows) or shared object (UNIX) allowing you to call an external function when replaying using the C interpreter. Once you load the DLL, you can call any function
defined in the DLL, without having to declare it.

You can specify a full path for the DLL.

On Windows platforms, if you do not specify a path,
lr_load_library searches for the DLL using the standard sequence used by the C++ function, LoadLibrary .

On UNIX platforms, you can set the LD_LIBRARY_PATH environment variable (or the platform equivalent). The
lr_load_dll function uses the same search rules as
dlopen. For more information, see the
man
pages for dlopen or its equivalent.

3. Loadruuner中DLL文件的使用

示例脚本如下:

int passwordLength;
char encryptedPassword[17];

lr_load_dll("EncryptLib.dll");

passwordLength=des3Encrypt(lr_eval_string("{password}"),encryptedPassword);//des3Encrypt函数为EncryptLib.dll库中的函数,函数详细说明需详见库文件的说明文档
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: