Discussion on the use of several HTML document interfaces Zhao Xiangning Problem: In the process of using the Active Accessibility SDK, I get the IHTMLDocument2 pointer from the handle of a window. Is there any way to get the IWEBBROWSER2 pointer from the IHTMLDocument2 pointer? I tried it in two interfaces (IHTMLDocument2 and iWebBBBBBBBROWSER2), but did not succeed. I also tried the iomnavigator * from GET_NAVIGATOR * with Netscape's HTMLWindow2 pointer. Also ended in failure. Please expert guidance. Solution: This problem is usually a common problem in COM programming. You have a window, document, or browser, you clearly know that you can get other information through these known data, but often run in the actual environment, Queryinterface always gives you back a fat NULL. The answer to this problem is actually hidden in the mysterious iServiceProvider interface, as the name suggests, the role of iServiceProvider is to provide services. IServiceProvider is a great interface: it has only one way - QueryService. If you use an ATL smart pointer, just like this. First, you must get the iServiceProvider interface, ccomqiptr
ISP-> QueryService (IID_IWEBBROWSERAPP, IID_IWEBBROWSER2, (void **) & IWB2); if you still don't understand what you are talking about, there is no relationship, normal. A fundamental rule for COM programming is: queryinterface must always return the interface of the object being queried. But the document does not implement the iWebBrowser2 interface, which only knows how to get the work that is working. Documents, browsers and windows are independent objects. Usually iServiceProvider is used in multiple separate and related COM object groups to implement some type of service. QueryInterface asked an object: "Do you implement this interface?", And QueryService tells a service provider, "No matter what object to implement this interface, you have to tell me." The interface pointer returned by QueryService is the same as the object of the query. It may also be different. As shown in the figure. All objects implement their own different interfaces and store pointers to another object. You must use the iServiceProvider interface to get an object of a specific interface, no matter which object it is. IServiceProvider :: QueryService To follow these internal pointers to get the interface object you want. Figure One multiple objects, an iServiceProvider From essentially, iServiceProvider is used to navigate the DHTML object level. Suppose you are writing an ActiveX control to navigate the object model. How do you do it? The first thing to query IoleClientSite below to get iServiceProvider: ccomqiptr
ISP-> QueryService (IID_IWEBBROWSERAPP, IID_IWEBBROWSER2, (Void **) & IWB2)); SID_SWEBBBROWSERAPP is a service label, but you can often see the code of IID_IWEBBBBBROWSERAPP as a service ID. Both usage can be done, because there is a macro definition in the