C-Preprocessor Requirements for MIDL

The MIDL compiler uses the C preprocessor during initial processing of the IDL file. The operating system used when you compile the IDL files is associated with a default C preprocessor. If you want to use a different C-preprocessor name, the MIDL compiler switch /cpp_cmd allows you to override the default C-preprocessor name:

midl /cpp_cmd cl386 filename

filename
Specifies the name of the IDL file.

During initial processing, the C preprocessor removes all preprocessor directives in the IDL file. After preprocessing, the only directive that can appear in a file is the #line directive in one of the following forms:

#line digit-sequence "filename" new-line
 
# digit-sequence "filename" new-line
 

Other directives should not appear in either the IDL file or any header file included by the IDL file. These other directives are not supported by the MIDL compiler and can cause errors. For a complete description of the line directive and other preprocessor directives, see your C-compiler documentation.

The MIDL compiler requires the C preprocessor to observe the following conventions:

Preprocessor directives present in the IDL file do not appear in the header file generated by the MIDL compiler. For example, any values defined in the IDL file with the C #define statement are removed by the C preprocessor. These #define statements will not appear in the header file generated by the MIDL compiler. If such values are defined only in the MIDL file and are required by C source files, the C compiler will report errors when it tries to compile these source files.

These are the four workarounds that are recommended:

To get a declaration in the generated header file with cpp_quote, use the following statement:

cpp_quote ("#define ARRSIZE 10");
 

This statement results in the following line being generated in the header file:

#define ARRSIZE 10
 

You can reproduce manifest constants using the constant-declaration syntax:

const short ARRSIZE = 10
 

This syntax results in the following line being generated in the header file:

#define ARRSIZE 10
 

You can define separate header files that contain only preprocessor directives and include them in both the IDL file and the C source files. Although the directives will not be available in the header file generated by the MIDL compiler, the C source program can include the separate header file.

You can also use enumeration constants in the IDL file. Enumeration constants are not removed during the early phases of MIDL compilation by the C-compiler preprocessor, so these constants are available in the header file generated by the MIDL compiler. For example, the statement

typedef enum midlworkaround { MAXSTRINGCOUNT = 300 };
 

will not be removed during MIDL compilation by the C preprocessor. The constant MAXSTRINGCOUNT is available to C source programs that include the header file generated by the MIDL compiler.