Click here to Skip to main content
13,054,615 members (57,752 online)
Click here to Skip to main content
Add your own
alternative version


37 bookmarked
Posted 15 Jul 2007

Basics of an IDL file

, 15 Jul 2007
Rate this:
Please Sign up or sign in to vote.
This article describes the basics of an IDL file.


MIDL (Microsoft Interface Definition Language) is used for describing COM objects. A file that contains interface and type library definitions is called an IDL file, and has a .idl file name extension.

The Interface Definition Language (IDL) is not a programming language, but a descriptive language to describe the interfaces being implemented by objects. IDL files are similar to C++ header files.

Contents of an IDL file

In any IDL file, there can be one or more interface definitions defined as part of a module. Each interface definition is composed of an interface header and an interface body. The IDL interface header specifies information about the interface as a whole.

The IDL interface body contains data types used in remote procedure calls and the function prototypes for the remote procedures. The interface body can also contain imports, pragmas, constant declarations, and type declarations. (Each interface body may contain methods, properties, variables/constants, enums etc. In other words, everything which needs to be exposed from the interface will be there in the IDL file.)

Structure of an IDL file

[ //header

  //Interface attributes go here.

interface INTERFACENAME //body

//The interface body goes here.

library TyeLibraryFileName
  //Type library Information


Interface header example

    helpstring("IConfig Interface"),

An iInterface header contains attributes that are platform-independent. Attributes in the interface header are global to the entire interface. These attributes are enclosed in square brackets at the beginning of the interface definition. Each attribute has its own meaning:

  • Object: This indicates that it is a COM interface.
  • Uuid: Represents a universally unique identifier (UUID) that is assigned to the interface and that distinguishes it from other interfaces. Each interface, class, and type library must be identified with its own unique identifier.
  • Dual: The dual attribute identifies an interface that exposes properties and methods through IDispatch and VTBL.
  • Nonextensible: This specifies that the IDispatch implementation includes only the properties and methods listed in the interface description, and that it cannot be extended with additional members at runtime.
  • Helpstring: A character string that is used to describe the element to which it applies.
  • Pointer_default: Specifies the default pointer attribute for all pointers except the top-level pointers that appear in the parameter lists.

For more information: MSDN.

Interface body example

interface ILogManager : IDispatch
    [id(1), helpstring("Initializes ILogManager")] HRESULT Initialize([in] IConfig* Config);

    [id(2), helpstring("Logs MemberClaims")] HRESULT LogMemberClaims([in] IMember* Member);

    [id(3), helpstring("Logs ILogData to specified destination")] 
            HRESULT Log([in] ILogData* LogData);

  • ILogManager – The interface name.
  • IDispatch – The COM base class.
  • Id(1) – The unique ID of the method.
  • Helpstring - The character string which describes this method.
  • HRESULT – Returns the error code.
  • Initialize – Method name.
  • In – Specifies the parameter to be passed from the calling procedure to the called procedure.
  • Out - The parameter that specifies data that is passed back to the caller. Using both directional attributes on one parameter specifies that the parameter is used both to send data to the method and to pass data back to the caller.

Type library

A type library is an essential part of a component, providing information to the compiler about the classes, interfaces, enumerations, and so on, included in the component. Type library files have the extension .tlb.

Example of a type library

library MyTypeLibraryFileLib
  helpstring("LogManager Class")
 coclass LogManager
  [default] interface ILogManager;

The library statement defines the MyTypeLibraryFileLib type library, which has its own uuid, helpstring, and version attributes. The coclass statement defines an entirely new component class, LogManager, that includes a previously defined interface, ILogManager.

MIDL compiler

An MIDL compiler processes the IDL file and creates a type library, a header, and proxy files.

A type library is a binary file that describes the COM object or COM interfaces, or both.

Creating a TLB file from an IDL file

Save the IDL file and then use the MIDL compiler to generate the TLB file. From the command line, enter:

midl myfilectl.idl /tlb myfilectl.tlb

The "/h" switch will produce a C/C++ header file as well.


  • Version 1.0 - created on 07-15-2007.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sabitha Abraham
Software Developer Microsoft
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
UDT30-Sep-13 20:41
memberUDT30-Sep-13 20:41 
QuestionMy vote of 4 Pin
Vijay Sringeri14-Jan-13 2:25
memberVijay Sringeri14-Jan-13 2:25 
GeneralMy vote of 1 Pin
Michael Chourdakis1-Jul-12 3:20
memberMichael Chourdakis1-Jul-12 3:20 
GeneralMy vote of 2 Pin
jcyangzh15-Apr-12 14:58
memberjcyangzh15-Apr-12 14:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 16 Jul 2007
Article Copyright 2007 by Sabitha Abraham
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid