How To Get IDispatch of an Excel or Word Document from an OCX (190985)
The information in this article applies to:
- Microsoft Excel 2000
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
- Microsoft Excel 2002
- Microsoft Excel 97 for Windows
- Microsoft Word 2002
- Microsoft Word 2000
- Microsoft Word 97 for Windows
This article was previously published under Q190985 SUMMARY
It is common for an OLE control to need the IDispatch of its container. You
can often get the IDispatch by using QueryInterface() from immediately
accessible interfaces on the server, such as IOleClientSite. However, for
some servers, such as Microsoft Excel, this approach fails.
Another way to get the IDispatch is by using the GetActiveObject() API to
get the server's IDispatch from the ROT. However, this method requires that
you must be able to obtain the CLSID or ProgID of the server. Furthermore,
ambiguous situations can occur where you can't distinguish between multiple
instances of the server.
This article uses another approach to obtain the IDispatch, which works for
both Microsoft Excel and Microsoft Word, even when multiple instances are
running.
The steps listed below allow you to build a control that can obtain the
IDispatch of the container's Document object.
Modification Type: | Minor | Last Reviewed: | 3/12/2005 |
---|
Keywords: | kbAutomation kbhowto KB190985 kbAudDeveloper |
---|
|