Define: Creating MFC Dialog DLLs for use with WinRunner

Define: Creating MFC Dialog DLLs for use with WinRunner

> Create a new MFC AppWizard(DLL) project, name it, and click <Next>.

> In the MFC AppWizard Step 1 of 1, accept the default settings and click <Finish>.

> Click <OK> in the New Project Information dialog.

> 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.

> You should see the constructor function C<project name>App(); double-click on it.

> 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 )

> Switch to the ResourceView tab in the ProjectView.

> Select Insert Resource from the VC++ IDE menu.

> Select Dialog from the Insert Resource dialog and click .

> 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.

> 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.

> The Class Wizard should appear with an \"Adding a Class\" dialog in front of it. Select \"Create a New Class\" and click .

> In the New Class dialog that comes up, give our new class a name and click <OK>.

> 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.

> 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.

> 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


> 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>.

> 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.

> In the tree on the ClassView tab, double-click on the constructor function for the C<project name>App (see step 5).

> 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;


> Choose Build <Project name>.DLL from the VC++ IDE menu.

> Fix any errors and repeat step 23.

> 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.

> 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).

> 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. 

Date:2002-02-09 00:00:00

Post Your Answers

User Email:

User Name:

Related TESTING Subjective Links

TESTING Subjective interview questions and answers for experienced and fresher