Importing System Header Files

Importing System Header Files

While it is often possible to use the #include directive to include header files in your IDL file, it is not recommended. The MIDL compiler will generate stubs for all functions defined in the IDL file being compiled. Usually a header file contains a number of prototypes that you neither need nor want to include in your stub files, and a #include effectively puts all those definitions into your main IDL file. Furthermore, if there are nonremotable types defined in the header file, the IDL file may not compile.

There are two ways to include type definitions from header files in an IDL file:

  • Use the import directive to include data types defined in a header file. Unlike the C-language #include directive, the import directive only picks up type and constant definitions and ignores procedure prototypes. This approach will work as long as your main IDL file does not reference any nonremotable types defined in the header file.
  • Create a helper IDL file with a dummy interface that includes the header files. Then, use the import directive to include the helper file. In this way, only the typedefs will appear in the compiled stubs. For example:
    //in helper.idl:
    interface dummy
      #include "kitchensink.h"
      #include "system.h"
    //in main.idl:
    import "helper.idl";



Community Additions

© 2016 Microsoft