In Class 3 - Create and Use a DLL

Create a DLL

In our problem we want to create a DLL for the right-button Listbox we have discussed. We will assume we have a programthat can use the right-button listbox. Click here for such a project. Follow these steps to create the dll project as part of the previous project.

  1. Add the dll complier directives to the right-button listbox header and comment out the rh include.
  2. Add the compiler directive
     #define RIGHT_BUTTON_LISTBOX_BUILDDLL 
    to your right-button listbox cpp file just above the line where you include the right-button listbox header.
  3. Select the show project node option from the environment options dialog.

  4. Select the project node, then select new target from the project menu.
  5. When the add target dialog appears type the same name as you used for the original node and select standard node type.

  6. In the target expert choose the project type as DLL and from the advanced options delete just the rc file.

  7. Paste the boiler plate code which you get by clicking here in the empty cpp file your new target has produced.
  8. Copy the text in the existing def file and paste into the new def file. Make changes suggested in comments.
  9. Add the right-button listbox cpp file to the dll target node.
  10. Shut off all debugging in this node
  11. Build and you should have a dll and lib file.

Use The DLL

We will add a right-button menu to the program we built in our first in-class lab. Click here to a completed version of that file. Complete the following steps and your window will have a right-button select.

  1. Create a new directory and extract the test program to this directory.
  2. Copy the right-button header, lib and dll files into the directory containing your project.
  3. Open the project and add the lib file to the project.
  4. Include the right-button listbox header in the file containing OurMain.
  5. Change the line
    _listbox = new TListBox(this, IDC_OUR_LISTBOX);
    to
    _listbox = new RightButtonListBox(this, IDC_OUR_LISTBOX);
    in the constructor for OurMain
  6. Add a right-button down hander in OurWindow that uses the following code
    	TDialog::EvRButtonDown(modKeys, point);	 // INSERT>> Your code here.	TMenu menu(HWindow);	HMENU hMenu = menu.GetSubMenu(0);	 // 0 is the first menu of this window,                                       				 // 1 would be the second etc.	TPopupMenu popupMenu(hMenu); // Create the Menu	GetCursorPos(point); // Put the menu at the click point	popupMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,point,0,HWindow);

At this point your program should run with a right-button select and menu.