[ interface-attribute-list ] interface interface-name
{
[ import import-file-list ; ... ]
[ cpp_quote("string") ... ]
[ const const-type identifier = const-expression ; ... ]
[ [ typedef ] [ [type-attribute-list] ] type-specifier declarator-list; ...]
[ [ [function-attr-list] ] type-specifier [pointer-declarator] function-name(
[ [parameter-attribute-list] ] type-specifier [declarator]
, ...
);
...
]
}
[ uuid(12345678-1234-1234-1234-123456789ABC),
version(3.1),
pointer_default(unique)
] interface IdlGrammarExample
{
import "windows.idl", "other.idl";
const wchar_t * NAME = L"Example Program";
typedef char * PCHAR;
HRESULT DictCheckSpelling(
[in, string] PCHAR word, // word to look up
[out] short * isPresent // 0 if not present
);
}
The IDL file contains the specification for the interface. The interface includes the set of data types and the set of functions to be executed from a remote location. Interfaces specify the function prototypes for remote functions and for many aspects of their behavior from the point of view of interface users.
Another file, the application configuration file (ACF), contains attributes that tailor the application for a specific operating environment. For more information, see ACF.
An interface specification consists of an interface header followed by an interface body. The interface header includes an attribute list describing characteristics that apply to the interface as a whole. The interface body contains the remote data types and function prototypes. The interface body also contains zero or more import lists, constant declarations, general declarations, and function declarators.
In Microsoft RPC, an IDL file can contain multiple interfaces and these interfaces can be forward declared (within the IDL file that defines them). For example:
interface ITwo; //forward declaration
interface IOne {
...uses ITwo...
}
interface ITwo {
...uses IOne...
}
Type definitions, construct declarations, and imports can occur outside of the interface body. All definitions from the main IDL file will appear in the generated header file, and all the procedures from all the interfaces in the main IDL file will generate stub routines. This enables applications that support multiple interfaces to merge IDL files into a single, combined IDL file.
As a result, it requires less time to compile the files and also allows MIDL to reduce redundancies in the generated stubs. This can significantly improve object interfaces through the ability to share common code for base interfaces and derived interfaces. For non-object interfaces, the procedure names must be unique across all the interfaces. For object interfaces, the procedure names only need to be unique within an interface. Note that multiple interfaces are not permitted when you use the /osf switch.
The syntax for declarative constructs in the IDL file is similar to that for C. MIDL supports all Microsoft C/C++ declarative constructs except:
x (y)
short x (y)
The import keyword specifies the names of one or more IDL files to import. The import directive is similar to the C include directive, except that only data types are assimilated into the importing IDL file.
The constant declaration specifies boolean, integer, character, wide-character, string, and void * constants. For more information, see const.
A general declaration is similar to the C typedef statement with the addition of IDL type attributes. Except in /osf mode, the MIDL compiler also allows an implicit declaration in the form of a variable definition.
The function declarator is a special case of the general declaration. You can use IDL attributes to specify the behavior of the function return type and each of the parameters.
arrays, const, enum, import, in, interface, MIDL Language Reference, out, pointers, struct, union