Page #41 (IDL Design Goals)

< BACK  NEXT >
[oR]

Processing IDL Files

We have come to terms that interfaces will be defined in a language called IDL. The interface definitions and the associated information are saved in a text file, referred to as an IDL file. This file generally has an extension of .idl. The question now is: What can we do with the IDL file in terms of developing the program code?

Let s look at the issues we need to address:

  • We need a mechanism to check the syntax of the newly defined interfaces.

  • A vast majority of components are developed in C++ language. The C++ language compiler cannot interpret IDL text, at least for now. We need to translate the interfaces into C++ abstract base classes to help the C++ compiler understand the interface syntax.

  • We need to generate the type library info, if need be.

  • We need to extract the marshaling information from the interface definition and generate proxy/stub code.

The SDK provides an executable, called MIDL.EXE, to accomplish the above-mentioned tasks. This executable, referred to as the MIDL compiler, is the primary consumer of an IDL file.

Typically, MIDL is executed as follows:

 Midl.exe  Oicf inputfile.idl 

The optional flags for MIDL are documented in the SDK. Flag Oicf causes MIDL to generate output that takes a considerably smaller memory footprint, resulting in better performance for Windows NT 4.0 and Windows 2000 OS.

Upon execution, the MIDL compiler will:

  • perform a syntactic check on the input file, generating error messages and warnings, if necessary

  • generate several output files. Figure 2.3 shows the generated output files for a sample IDL file, Video.idl

    Figure 2.3. Output files from MIDL.
    graphics/02fig03.gif

By default, the generated files, except for DllData.c, have names prefixed with the base filename of the IDL file. However, MIDL has command line switches to rename each type of output file.

Based on the functionality, the output files can be divided into three groups: C/C++ development files, type library files, and proxy-stub files.

C/C++ Development Files

These files contain C/C++ equivalent declarations for the interfaces and other constructs defined in the IDL file:

Video.h: This header file contains C/C++ declarations for the interfaces and extended data types such as structures, enumerations, etc. Any GUID used in the IDL file (for interfaces, classes, libraries, etc.) is represented as an external variable in this header file. By convention, an interface ID is represented as IID_<InterfaceName>, a class ID is represented as CLSID_<ClassName>, and a library ID is represented as LIBID_<LibraryName>. For our video example, the defined variables look like:

 EXTERN_C const IID IID_IVideo;  EXTERN_C const IID IID_ISVideo;  EXTERN_C const IID LIBID_VcrLib;  EXTERN_C const CLSID CLSID_VCR; 

Video_i.c: Contains the actual values of the GUID variables that were declared as extern in the header file. When some piece of code refers to any GUID declared as EXTERN_C in the header file, the code has to be linked with Video_i.obj (the compiler generated object file for Video_i.c) to resolve the symbols.

Type Library Files

The type library file typically has an extension .tlb. For our video example, the output file is Video.tlb.

The type library file has many uses, including the following:

  • VB can read the type library and make the interface information available within the development environment.

  • With some restrictions that we will cover later, a type library can also be used for marshaling interfaces.

  • Visual C++ compiler provides native support to read the type library and generate code to simplify accessing the defined interfaces.

graphics/01icon01.gif

The Visual Basic development environment provides a tool called Object Browser that lets you view an object s type library information. Saving help strings in the type library ensures that such development environments get to display descriptive information about the interface and its methods.


Proxy-Stub Files

These files contain code for creating a proxy-stub DLL. A proxy-stub DLL is itself a COM server containing COM objects that implement the marshaling logic for the interfaces defined in the IDL file.

Video_p.c: Contains code to create proxy and stub, and to marshal/unmarshal the interfaces defined in file Video.idl.

Dlldata.c: Contains the DLL entry points required by a COM object server.

The proxy-stub code has to be compiled and linked to create the proxy-stub DLL. This DLL has to be registered on both the client and server machine.


< BACK  NEXT >


COM+ Programming. A Practical Guide Using Visual C++ and ATL
COM+ Programming. A Practical Guide Using Visual C++ and ATL
ISBN: 130886742
EAN: N/A
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net