Interview Questions

Creating MFC Dialog DLLs for use with WinRunner

Mercury WinRunner FAQ

(Continued from previous question...)

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
// 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()
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)
<dialog class> theDlg;
theDlg.<var1>=<initial value>;
<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.

(Continued on next question...)

Other Interview Questions