IDispatch: Difference between revisions
m Made IDispatch MSDN link into a proper reference |
→External links: Removed dead external link |
||
(13 intermediate revisions by 11 users not shown) | |||
Line 1: | Line 1: | ||
{{ |
{{More footnotes|date=March 2010}} |
||
'''IDispatch''' is the [[Interface (computer science)|interface]] that exposes the [[OLE Automation]] protocol.<ref>Microsoft MSDN: [http://msdn.microsoft.com/en-us/library/ms221608.aspx IDispatch interface]</ref> |
'''IDispatch''' is the [[Interface (computer science)|interface]] that exposes the [[OLE Automation]] protocol.<ref>Microsoft MSDN: [http://msdn.microsoft.com/en-us/library/ms221608.aspx IDispatch interface]</ref> Extending [[IUnknown]], it is one of the standard interfaces that can be exposed by [[Component Object Model|COM]] objects. COM distinguishes between three interface types: ''custom'' that are VTABLE-based IUnknown interfaces, ''dispatch'' that are IDispatch interfaces supporting introspection, and ''dual'' interfaces supporting both types. |
||
The Automation (IDispatch) interface allows a client application to find out what properties and methods are supported by an object at run-time, i.e. implements the concept of [[Run- |
The Automation (IDispatch) interface allows a client application to find out what properties and methods are supported by an object at run-time, i.e. implements the concept of [[Run-time type information|RTTI]]. It also provides the information necessary to invoke these properties and methods. Client applications do not need to be aware of the object members when they are compiled. This allows COM and ActiveX objects to be called by scripting programs platforms such as the [[Active Server Pages|ASP]] server and [[JavaScript]] on [[Internet Explorer]], where calling conventions were not known at the time [[Internet Information Services|IIS]] or IE were built. By contrast, a simple object library is compiled and linked into a program, e.g. a DLL call needs to know a function name and parameters at compile time. |
||
⚫ | A script writer can ask the COM object for a method or property it already knows about from documentation. Then, the client can execute the function with Invoke provided by the IDispatch interface, a form of [[Late binding|late-binding]]. This sort of capability was also supported by [[Dynamic Data Exchange]] (DDE), which never became popular due to being too low-level. |
||
⚫ | Each property and method implemented by an object that supports the IDispatch interface has what is called a Dispatch ID, which is often abbreviated DISPID. The DISPID is the primary means of identifying a property or method and must be supplied to the ''Invoke'' function for a property or method to be invoked, along with an array of [[Variant type|Variant]]s containing the parameters. The ''GetIDsOfNames'' function can be used to get the appropriate DISPID from a property or method name that is in [[String (computer science)|string]] format. |
||
⚫ | ''Dispatch'' interfaces are flexible, but suffer from additional introspection and invocation overhead compared to ''custom'' interfaces.<ref>Microsoft MSDN: [http://www.microsoft.com/msj/1295/activex1295.aspx ActiveX/COM Q&A December 1995]</ref> It is therefore often a good idea to support both interface types with ''dual'' interfaces. That way, clients supporting VTABLE-based invocation can use the ''custom'' interface instead of the ''dispatch'' counterpart. |
||
⚫ | A script writer can ask the COM object for a method or property it already knows about from documentation. Then, the client can execute the function with Invoke provided by the IDispatch interface, a form of [[Late binding|late-binding]]. This sort of capability was also supported by [[Dynamic Data Exchange]] (DDE), which never became popular due to being too low-level. |
||
==Methods== |
|||
⚫ | Each property and method implemented by an object that supports the IDispatch interface has what is called a Dispatch ID, which is often abbreviated DISPID. The DISPID is the primary means of identifying a property or method and must be supplied to the ''Invoke'' function for a property or method to be invoked, along with an array of [[Variant type (COM)|Variant]]s containing the parameters. The ''GetIDsOfNames'' function can be used to get the appropriate DISPID from a property or method name that is in [[String (computer science)|string]] format. |
||
IDispatch derives from [[IUnknown]] and extends it with four additional methods: |
IDispatch derives from [[IUnknown]] and extends it with four additional methods: |
||
< |
<syntaxhighlight lang="cpp"> |
||
interface IDispatch : public IUnknown { |
interface IDispatch : public IUnknown { |
||
virtual HRESULT GetTypeInfoCount(unsigned int * pctinfo) = 0; |
virtual HRESULT GetTypeInfoCount(unsigned int * pctinfo) = 0; |
||
Line 32: | Line 35: | ||
) = 0; |
) = 0; |
||
}; |
}; |
||
</syntaxhighlight> |
|||
</source> |
|||
The '''IDispatch''' [[interface ID]] is defined as a [[Globally unique identifier|GUID]] with the value of {00020400-0000-0000-C000-000000000046}. |
The '''IDispatch''' [[interface ID]] is defined as a [[Globally unique identifier|GUID]] with the value of {00020400-0000-0000-C000-000000000046}. |
||
⚫ | ''Dispatch'' interfaces are flexible, but |
||
==References== |
==References== |
||
Line 41: | Line 42: | ||
==External links== |
==External links== |
||
*[http://disphelper.sourceforge.net/ DispHelper], an [[open-source]] library to help using an IDispatch from C or C++. |
*[http://disphelper.sourceforge.net/ DispHelper], an [[open-source model|open-source]] library to help using an IDispatch from C or C++. |
||
*[http://be-sure-soft.com/idispatchcodegenerator/ IDispatchCodeGenerator], Code generator. Feature that adds IDispatch to an object. Language is C++. |
|||
[[Category:Object-oriented programming]] |
[[Category:Object-oriented programming]] |
||
[[Category:Microsoft application programming interfaces]] |
[[Category:Microsoft application programming interfaces]] |
||
{{windows-stub}} |
Latest revision as of 22:22, 14 November 2023
This article includes a list of general references, but it lacks sufficient corresponding inline citations. (March 2010) |
IDispatch is the interface that exposes the OLE Automation protocol.[1] Extending IUnknown, it is one of the standard interfaces that can be exposed by COM objects. COM distinguishes between three interface types: custom that are VTABLE-based IUnknown interfaces, dispatch that are IDispatch interfaces supporting introspection, and dual interfaces supporting both types.
The Automation (IDispatch) interface allows a client application to find out what properties and methods are supported by an object at run-time, i.e. implements the concept of RTTI. It also provides the information necessary to invoke these properties and methods. Client applications do not need to be aware of the object members when they are compiled. This allows COM and ActiveX objects to be called by scripting programs platforms such as the ASP server and JavaScript on Internet Explorer, where calling conventions were not known at the time IIS or IE were built. By contrast, a simple object library is compiled and linked into a program, e.g. a DLL call needs to know a function name and parameters at compile time.
A script writer can ask the COM object for a method or property it already knows about from documentation. Then, the client can execute the function with Invoke provided by the IDispatch interface, a form of late-binding. This sort of capability was also supported by Dynamic Data Exchange (DDE), which never became popular due to being too low-level.
Dispatch interfaces are flexible, but suffer from additional introspection and invocation overhead compared to custom interfaces.[2] It is therefore often a good idea to support both interface types with dual interfaces. That way, clients supporting VTABLE-based invocation can use the custom interface instead of the dispatch counterpart.
Methods
[edit]Each property and method implemented by an object that supports the IDispatch interface has what is called a Dispatch ID, which is often abbreviated DISPID. The DISPID is the primary means of identifying a property or method and must be supplied to the Invoke function for a property or method to be invoked, along with an array of Variants containing the parameters. The GetIDsOfNames function can be used to get the appropriate DISPID from a property or method name that is in string format.
IDispatch derives from IUnknown and extends it with four additional methods:
interface IDispatch : public IUnknown {
virtual HRESULT GetTypeInfoCount(unsigned int * pctinfo) = 0;
virtual HRESULT GetTypeInfo(unsigned int iTInfo,
LCID lcid,
ITypeInfo ** ppTInfo
) = 0;
virtual HRESULT GetIDsOfNames(REFIID riid,
OLECHAR ** rgszNames,
unsigned int cNames,
LCID lcid,
DISPID * rgDispId
) = 0;
virtual HRESULT Invoke(DISPID dispIdMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS * pDispParams,
VARIANT * pVarResult,
EXCEPINFO * pExcepInfo,
unsigned int * puArgErr
) = 0;
};
The IDispatch interface ID is defined as a GUID with the value of {00020400-0000-0000-C000-000000000046}.
References
[edit]- ^ Microsoft MSDN: IDispatch interface
- ^ Microsoft MSDN: ActiveX/COM Q&A December 1995
External links
[edit]- DispHelper, an open-source library to help using an IDispatch from C or C++.