OOPortal OOPortal

ATL Development   «Prev  Next»

Add idl Definitions - Exercise

Add the definitions of NAME_SIZ and PhRec to PhBook.idl

Objective: Add the definitions of NAME_SIZ and PhRec to PhBook.idl.


Part 1: Add the definitions of NAME_SIZ and PhRec into PhBook.idl
  1. Go to the File View tab of the project workspace. Double-click on PhBook.idl to open it.
  2. Just below line import ocidl.idl and above the attributes section (i.e., [object, ...]) of IReadPhBook, add the following:
    cpp_quote("#define NAME_SIZ 80")
    #define NAME_SIZ 80
    typedef struct {
    TCHAR firstName[NAME_SIZ];
    TCHAR lastName[NAME_SIZ];
    TCHAR phNumber[NAME_SIZ];
    } PhRec;
  3. Save PhBook.idl.
  4. In the File View tab, right-click PhBook.idl and select to compile PhBook.idl.
  5. Recall from our study of core COM concepts that compiling an IDL file creates several files, including an include file. Successfully compiling PhBook.idl creates file PhBook.h. Open PhBook.h (using File->Open) to see how MIDL has converted IDL into C++ (and C) constants and declarations.
  6. Copy the contents of PhBook.idl and PhBook.h into the text area and click OK, Submit
Part 2: Build the project
  1. Make sure the project builds without errors.
  2. In an ATL project, if the build is successful, the server is automatically registered.

Exercise scoring

This exercise is worth a total of 10 points if PhBook.idl compiles and PhBook.h contains NAME_SIZ and PhBook definitions.

Tutor submission

Click Submit to submit this exercise.