Share via


Creating the IDispatch Interface

The IDispatch interface provides a late-bound mechanism to access and retrieve information about an object's methods and properties. In addition to the member functions inherited from IUnknown, the following member functions should be implemented within the class definition of each object that will be exposed through Automation.

  • GetTypeInfoCount — Returns the number of type descriptions for the object. For objects that support IDispatch, the type information count is always 1.

  • GetTypeInfo — Retrieves a description of the object's programmable interface.

  • GetIDsOfNames — Maps the name of a method or property to a DISPID, which can later be used to invoke the method or property.

  • Invoke — Calls one of the object's methods, or gets or sets one of its properties.

You can implement IDispatch by any of the following means:

  • Delegating to the DispInvoke and DispGetIDsOfNames functions, or to ITypeInfo::Invoke and ITypeInfo::GetIDsOfNames. This is the recommended approach, because it supports multiple locales and allows exceptions to be returned.

  • Calling the CreateStdDispatch function. This approach is the simplest, but it does not provide for rich error handling or multiple national languages.

  • Implementing the member functions without delegating to the dispatch functions. This approach is seldom necessary. Because Invoke is a complex interface with many subtle semantics that are difficult to emulate, it is strongly recommended that code delegate toITypeInfo::Invoke to implement this mechanism.