const const-type identifier = const-expression ;
/* IDL file typedef syntax */
[ typedef [ , type-attribute-list ] ] const const-type declarator-list;
[ typedef [ , type-attribute-list ] ] pointer-type const declarator-list;
[ [ function-attr-list ] ] type-specifier [ ptr-decl ] function-name(
[ [ parameter-attribute-list ] ] const const-type [declarator],
[ [ parameter-attribute-list ] ] pointer-type const [declarator]
, ...
);
const void * p1 = NULL;
const char my_char1 = 'a';
const char my_char2 = my_char1;
const wchar_t my_wchar3 = L'a';
const wchar_t * pszNote = L"Note";
const unsigned short int x = 123;
typedef [string] const char *LPCSTR;
HRESULT GetName([out] wchar_t * const pszName );
MIDL allows you to declare constant integer, character, string, and boolean types in the interface body of the IDL file. You can use the const keyword to modify the type of a type declaration or the type of a function parameter. Const type declarations are reproduced in the generated header file as #define directives.
DCE IDL compilers do not support constant expressions. Therefore this feature is not available when you use the MIDL compiler /osf switch.
A previously defined constant can be used as the assigned value of a subsequent constant. The value of a constant integral expression is automatically converted to the respective integer type in accordance with C conversion rules.
The value of a character constant must be a single-quoted ASCII character. When the character constant is the single-quote character itself ('), the backslash character (\) must precede the single-quote character, as in \'.
The value of a character-string constant (char *) must be a double-quoted string. Within a string, the backslash (\) character must precede a literal double-quote character ( " ), as in \". Within a string, the backslash character (\) represents an escape character. String constants can consist of up to 255 characters.
The value NULL is the only valid value for constants of type void *. Any attributes associated with the const declaration are ignored.
The MIDL compiler does not check for range errors in const initialization. For example, when you specify "const short x = 0xFFFFFFFF;" the MIDL compiler does not report an error and the initializer is reproduced in the generated header file.