The IDL Interface Body

The interface body contains data types used in remote procedure calls and the function prototypes for the procedures to be executed remotely. The interface body can contain imports, pragmas, constant declarations, type declarations, and function declarations. In Microsoft-extensions mode, the MIDL compiler also allows implicit declarations in the form of variable definitions.

Base Types

Base types are the fundamental data types of MIDL. Other types in the interface must be derived from base types or from predefined types.

For example, MIDL restricts the use of the void * data type because the size of this type is not fixed. The automatically generated stubs must know the exact size of every data item to be transmitted.

The boolean type is an 8-bit data item that is implemented by the MIDL compiler as an unsigned char. In keeping with commonly followed programming practices, MIDL implements FALSE as zero and TRUE as 1. When you use the Microsoft-extensions mode of the MIDL compiler, boolean initializations using zero and 1 are allowed in addition to TRUE and FALSE. However, in DCE-compatibility mode, only the values TRUE and FALSE are allowed. Note that if you are using MIDL to generate a type library, the boolean data type is not compatible with the oleautomation attribute. You will need to use VARIANT_BOOL in Automation-compatible interfaces.

The byte type consists of 8 bits. The byte type is considered opaque data and, consequently, the value is not converted on transmission.

The char type is an unsigned 8-bit entity that maps to the unsigned char in C. MIDL translates all char types in the IDL file to unsigned char types in the generated header file. The user can change the default sign of char on the target system with the /char switch.

The handle_t type is used to declare a primitive handle in a type declaration or in a parameter list. Objects of type handle_t are not transmitted on the network.

The void keyword is valid in a function declaration or in a pointer declaration. In a function declaration, it designates a procedure with no arguments or a procedure that does not return a result. In a pointer declaration, void can only be used with the context_handle attribute.

The keyword int designates a 32-bit integer on 32-bit platforms. On 16-bit platforms you must use one of the following integer modifiers and the int keyword is optional. The hyper keyword designates a 64-bit integer, the long keyword a 32-bit integer, the short keyword a 16-bit integer, and the small keyword an 8-bit integer. For more information, see signed and unsigned.

The float keyword designates a 32-bit floating-point number and the double keyword designates a 64-bit floating-point number. For more information, see signed and unsigned.

Predefined Types

The predefined types error_status_t and wchar_t are derived from the MIDL base types. The predefined type wchar_t is a wide-character type and is defined as an unsigned short. The predefined type error_status_t is the data type returned by the stubs when the stubs encounter a run-time error.

Attributes specify how data is managed on the network. For example, when the function parameter represents a pointer, array, or union, the attributes direct the generation of stub code that packages the data for network transmission.

The import Directive

The import directive is closely related to the #include C-preprocessor macro. It directs the compiler to include, at the point of import, the data types defined in the imported files and to make them available for use in the interface. In contrast to the C #include macro, the import directive ignores procedure prototypes defined in imported files.

Pragmas

C-preprocessing directives such as #define are expanded by the C preprocessor during MIDL compilation and are not available at C-compile time. To avoid losing these C-preprocessor macro definitions, use the cpp_quote or pragma midl_echo directive. These directives take quoted strings as parameters and instruct the MIDL compiler to emit the parameter string into the generated header file in the same lexical position relative to other interface components.

Constant Declarations

Constant declarations allow you to associate a constant value with an identifier and use the identifier as part of an expression. Constant declarations are generated as #define statements in the header file. The MIDL compiler does not perform any range checking on integral expressions.

Constant declarations are limited to integral char, boolean, wchar_t, wchar_t *, char *, and void * types. The constant value is an expression whose operands are all constant integer literals, boolean expressions that are computable at compile time, or single characters or strings, depending on the const type. For more information, see const.