The DLL I’ll create here is a simple stub with a few basic functions and can serve as a template for any type of DLL that you want to create.
I’ll show how to avoid the most common problems of sending/retrieving strings to/from the DLL as well as how to handle the Unicode situation with D2009 and D2010 (LR is not Unicode enabled).
Some of the things a LR DLL developer needs to remember are:
LR is Muti-Threaded and Multi-processed, make the DLL thread-safe
When using LoadGenerators the DLL must be distributed to several machines
When using Performance Center the lr_load_dll() function needs to be white-listed on every LoadGenerator. The file to manipulate is “C:\Program Files\HP\Load Generator\merc_asl\lrun_api.asl”
The DLL may be unloaded at any time, if the script fails/aborts (=> YOU must release allocated memory)
If eternal loops or lockups inside the DLL occur, the whole controller/loadgenerator is lost until rebooted (really bad when under PerfCenter)
Keeping the above in mind, also remember the following general rules
LR script makers make mistakes too by sending INVALID input to functions or using them in an unintended way. This means that you as a DLL developer NEED TO VERIFY the input params for every function call!
The DLL may be installed on a variety of windows platforms (Win2000->Win7) so make sure you check the OS Version if you are using Windows API calls that are version dependent
There is no guarantee that the DLL has Administrator privilidges!
The DLL is restricted to the same Win32 memory as the host process (2 Gig max allocation)
Creating the DLL in Delphi
Close all projects and then choose “FILE | OTHER …“, select “DELPHI PROJECTS” and then “Dynamic Link Library“. You should now have the following skeleton (excluding all comments):
1
libraryProject1;
2
uses
3
SysUtils,
4
Classes;
5
{$R *.res}
6
begin
7
end.
Now copy & paste the following instead of the above:
001
libraryMyDLL;
002
003
uses
004
SysUtils, Classes, Windows,
005
VUManager in'VUManager.pas';
006
007
Const
008
{ Version Constants }
009
DLLVer_Major = 1;
010
DLLVer_Minor = 0;
011
DLLVer_Copyright = 'Copyright (C) by Celarius Oy';
You can now save the project as “MyDLL” in a folder of your choice.
Now we’ll need to create the VUManager unit with “FILE | NEW UNIT” and save the new unit as “VUManager.pas” in the same directory as the rest of the Delphi files. Copy & Paste the following into the new unit.
请发表评论