ATL Development   «Prev  Next»
Lesson 10 Adding structures and constants
Objective Add structure PhRec into PhBook.idl.

Adding Structures Constants

Now that we've designed data structures, properties, and methods for PhBook, it is time to begin writing code. Our next steps are to add the definition of NAME_SIZ and PhRec into PhBook.idl because both the client and the server use these definitions.
NAME_SIZ and PhRec must be manually added into PhBook.idl. Adding the following code to PhBook.idl just below import ocidl.idl and above the attributes section does this:

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;

The cpp_quote directive tells MIDL (the IDL compiler) not to compile the enclosed string. Instead, the string should be passed through into output file PhRec.h. cpp_quote directives are commonly used by developers to place constants, macros, and comments into the include file created by MIDL.
The #define NAME_SIZ 80, not enclosed within cpp_quote, is used by MIDL as a constant.
After compiling the definitions above, MIDL generates the following code, placing it in PhRec.h:

#define NAME_SIZ 80
typedef /* [public] */ struct
    TCHAR firstName[ 80 ];
    TCHAR lastName[ 80 ];
    TCHAR phNumber[ 80 ];
    } PhRec;
In the next lessons, we will add properties CurRec, MaxRecs, and NumRecs and methods IReadPhBook::GetPhoneRec, IManagePhBook::AddRec, and IManagePhBook::DeleteRec. These can be added using Visual C++ support.

Add Idl Definitions - Exercise

Click the Exercise link below to apply what you've learned about adding structures and constants.
Add IDL Definitions - Exercise