Partager via


Accessing the Containing Application

Embedded objects that require access to the Application object of their container (the top-level programmability object for the process) should use the ServiceProvider interfaces to access it.

Containers should implement IServiceProvider with the same implementation as with IOleClientSite, and at the minimum, should support SID_Application. If the container can also be embedded, use its container's IServiceProvider implementation to access the Application object. If an error occurs, embedded objects should perform a QueryInterface on IOleClientSite for IServiceProvider and use IServiceProvider to request SID_Application.

The standards for Automation specify that document-level objects in an application's programmability model should support the Parent and Application properties. If this also doesn't work (because the immediate container does not support IServiceProivder, or SID_Application), an embedded object can access the containing application by calling IOleClientSite::GetContainer, QueryInterface(IID_IDispatch), followed by GetIDsOfNames. This gets the DISPID for the Parent or Application property.