Software QA FYI - SQAFYI

Mercury WinRunner FAQ

Part:   1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34   35  36  37  38  39  40  41  42  43  44  45 

Q: Creating C++ DLLs for use with WinRunner

Here are the steps for creating a C++ DLL:
1. Create a new Win32 Dynamic Link Library project, name it, and click <Next>.
2. On Step 1 of 1, select "An Empty DLL Project," and click <Finish>.
3. Click <OK> in the New Project Information dialog.
4. Select File New from the VC++ IDE.
5. Select C++ Source File, name it, and click .
6. Double-click on the .cpp file to open it.
7. Create your functions in the following format:

#include "include1.h"
#include "include2.h"
.
.
.
#include "includen.h"

#define EXPORTED extern "C" __declspec(dllexport)

EXPORTED <return type> <function1 name>(<type arg1> <arg1>,
<type arg2> <arg2>,
…,
<type argn> <argn>)
{
<function body>
return <some value>;
}
.
.
.
EXPORTED <return type> <functionN name>(<type arg1> <arg1>,
<type arg2> <arg2>,
…,
<type argn> <argn>)
{
<function body>
return <some value>;
}

8. Choose Build <Project name>.DLL from the VC++ IDE menu.
9. Fix any errors and repeat step 8.
10. Once the DLL has compiled successfully, the DLL will be built in either a Debug directory or a Release directory under your project folder depending on your settings when you built the DLL.
11. To change this setting, select Build Set Active Configuration from the VC++ IDE menu, and select the Configuration you want from the dialog. Click <OK>, then rebuild the project (step 8).
12. All the DLLs types that you are going to create are loaded and called in the same way in WinRunner. This process will be covered once in a later section.


Q: Creating MFC DLLs for use with WinRunner

1. Create a new MFC AppWizard(DLL) project, name it, and click <Next>.
2. In the MFC AppWizard Step 1 of 1, accept the default settings and click <Finish>.
3. Click <OK> in the New Project Information dialog.
4. Select the ClassView tab in the ProjectView and expand the classes tree. You will see a class that has the following name C<project name>App; expand this branch.
5. You should see the constructor function C<project name>App(); double-click on it.
6. This should open the .cpp file for the project. At the very end of this file add the following definition:
#define EXPORTED extern "C" __declspec( dllexport )
7. Below you will add your functions in the following format:
#define EXPORTED extern "C" __declspec(dllexport)
EXPORTED <return type> <function1 name>(<type arg1> <arg1>,
<type arg2> <arg2>,
…,
<type argn> <argn>)
{
<function body>
return <some value>;
}
.
.
.
EXPORTED <return type> <functionN name>(<type arg1> <arg1>,
<type arg2> <arg2>,
…,
<type argn> <argn>)
{
<function body>
return <some value>;
}

8. You will see the functions appear under the Globals folder in the ClassView tab in the ProjectView.
9. Choose Build <Project name>.DLL from the VC++ IDE menu.
10. Fix any errors and repeat step 9.
11. Once the DLL has compiled successfully, the DLL will be built in either a Debug directory or a Release directory under your project folder depending on your settings when you built the DLL.
12. To change this setting, select Build Set Active Configuration from the VC++ IDE menu, and select the Configuration you want from the dialog. Click , then rebuild the project (step 9).
13. All the DLLs types that you are going to create are loaded and called in the same way in WinRunner. This process will be covered once in a later section.


Q: Creating MFC Dialog DLLs for use with WinRunner

1. Create a new MFC AppWizard(DLL) project, name it, and click <Next>.
2. In the MFC AppWizard Step 1 of 1, accept the default settings and click <Finish>.
3. Click <OK> in the New Project Information dialog.
4. Select the ClassView tab in the ProjectView and expand the classes tree. You will see a class that has the following name C<project name>App; expand this branch also.
5. You should see the constructor function C<project name>App(); double-click on it.
6. This should open the .cpp file for the project. At the very end of this file add the following definition:
#define EXPORTED extern "C" __declspec( dllexport )

7. Switch to the ResourceView tab in the ProjectView.
8. Select Insert Resource from the VC++ IDE menu.
9. Select Dialog from the Insert Resource dialog and click .
10. The Resource Editor will open, showing you the new dialog. Add the controls you want to the dialog, and set the properties of the controls you added.
11. Switch to the ClassView tab in the ProjectView and select View ClassWizard from the VC++ IDE menu, or double-click on the dialog you are creating.
12. The Class Wizard should appear with an "Adding a Class" dialog in front of it. Select "Create a New Class" and click .
13. In the New Class dialog that comes up, give your new class a name and click <OK>.
14. In the Class Wizard, change to the Member Variables tab and create new variables for the controls you want to pass information to and from. Do this by selecting the control, clicking , typing in the variable name, selecting the variable type, and clicking <OK>. Do this for each variable you want to create.
15. Switch to the Message Maps tab in the Class Wizard. Select the dialog class from the Object IDs list, then select the WM_PAINT message from the Messages List. Click <Add Function>, then <Edit Code>. This should bring up the function body for the OnPaint function.
16. Add the following lines to the OnPaint function so it looks like the following:
void <the dialog class>::OnPaint()
{
CPaintDC dc(this); // device context for painting
this-%gt;BringWindowToTop();
UpdateData(FALSE);
// Do not call CDialog::OnPaint() for painting messages
}

17. Select IDOK from the Object IDs list, then select the BN_CLICKED message from the Messages
list. Click <Add Function>, accept the default name, and click <Edit Code>.
18. Add the line UpdateData(TRUE); to the function, so it looks like this:
void ::OnOK()
{
UpdateData(TRUE);
CDialog::OnOK();
}
19. When you are done with this, click <OK> to close the Class Wizard dialog and apply your changes. Your new class should appear in the ProjectView in the ClassView tab.
20. In the tree on the ClassView tab, double-click on the constructor function for the C<project name>App (see step 5).
21. At the top of the file, along with the other includes, add an include statement to include the header file for your dialog class. It should be the same name as the name you gave the class in step 13 with a .h
appended to it. If you are unsure of the name, you can look it up on the FileView tab under the Header Files folder. 22. At the very end of the file, after the #define you created in step 6, create a function that looks something like this:
EXPORTED int create_dialog(char* thestring)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
<dialog class> theDlg;
theDlg.<var1>=<initial value>;
theDlg.DoModal();
<do whatever conversion is necessary to convert the value to a string>
strcpy(thestring,strVar1); //this will pass the value back to WinRunner.
return 0;
}
23. Choose Build <Project name>.DLL from the VC++ IDE menu.
24. Fix any errors and repeat step 23.
25. Once the DLL has compiled successfully, the DLL will be built in either a Debug directory or a Release directory under your project folder depending on your settings when you built the DLL.
26. To change this setting, select Build Set Active Configuration from the VC++ IDE menu, then select the Configuration you want from the dialog. Click <<OK>, then rebuild the project (step 23).
27. All the DLLs types that you are going to create are loaded and called in the same way in WinRunner. This process will be covered once in a later section.


Q: Loading and Calling the Above DLLs from WinRunner

Loading and calling DLLs from WinRunner is really very simple. There are only 3 steps.
1. Load the DLL using the command load_dll.
2. Declare the function in the DLL as an external function using the extern function.
3. Call the function as you would any other TSL function.
As simple as this is, there are some things you need to be aware of.
1. WinRunner has a limited number of variable types; basically, there is string, int, and long. Windows has many different types. Two common types, which may confuse you, are HWND and DWORD. Which WinRunner type do you choose for these? You should declare these as long.
2. If you are building a function in a DLL and you are testing it in WinRunner, make sure you unload the DLL in WinRunner using the unload_dll function before you try to recompile the DLL. If you leave the DLL loaded in WinRunner and try to recompile the DLL, you will receive an error message in VC++ that looks like this:
LINK : fatal error LNK1104: cannot open file "Debug/<project name>.DLL Error executing link.exe
To resolve this error, step through the unload_dll line in WinRunner, then compile the DLL.
3. Before shipping a DLL make sure you compile it in Release mode. This will make the DLL much smaller and optimized.

Part:   1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34   35  36  37  38  39  40  41  42  43  44  45 

Mercury WinRunner FAQ