In Raymond's demonstration of how to hop around some shell objects, he first obtains an IWebBrowser2
(or technically IWebBrowserApp
), and then uses QueryService
to get to SID_STopLevelBrowser
. I was wondering if anyone can explain conceptually what those two things are and how they're related. Is one inside the other within an Explorer window? Thanks for any info.
-
1Now you should now what IServiceProvider is for: https://stackoverflow.com/questions/59432866/understanding-iserviceprovider-and-queryservice and SID_STopLevelBrowser is (ancient knowledge) documented in an old Microsoft KB article (Q257717 "How To Retrieve the Top-Level IWebBrowser2 Interface from an ActiveX Control") that's been gone now, but you can find on wayback machine: https://web.archive.org/web/20140417005545/https://support.microsoft.com/kb/257717 – Simon Mourier Dec 27 '19 at 15:13
-
So there are actually two `IWebBrowser2`s? I don't understand. Can you perhaps explain the hierarchy of objects? Also it seems that `SID_STopLevelBrowser` is misleading, because the article suggests that `IWebBrowser2` is on a higher level. Is that correct? – Dec 27 '19 at 15:23
-
Any COM interface can be implemented by any class, event if it's not specifically documented (and it's getting worse... we have to use wayback machine). SID_STopLevelBrowser ensures you get the top level one, from any one in the hierarchy. There's basically no more documentation. – Simon Mourier Dec 27 '19 at 16:33
-
2This is about 1996, Microsoft was caught somewhat by surprise by the Internet revolution. Trying to catch up, they tried to make the distinction between Explorer and a browser disappear. That did not turn out well, they're kinda stuck with maintaining compatibility for old programs. They can only delete the docs to discourage anybody from still using it. Do feel free to be discouraged. – Hans Passant Dec 27 '19 at 19:39
1 Answers
SID_STopLevelBrowser
is just a GUID telling QueryService
(in this case) which hierarchy object you are interested in. What you are really asking about is; what is the difference between IWebBrowser
and IShellBrowser
.
IWebBrowser
is a Internet Explorer object but when Explorer.exe gained web support in Win98/IE4, a plain Explorer.exe also gained the ability to host web pages (this ability was disabled/deprecated in Vista). The top level (SID_STopLevelBrowser
) IShellBrowser
on the other hand is the classic "host" object that hosts IShellView
(the file list in all versions of Explorer):
Implemented by hosts of Shell views (objects that implement IShellView). Exposes methods that provide services for the view it is hosting and other objects that run in the context of the Explorer window.
Users of Windows 95 could choose to install IE4 without the shell update and on those systems there is full separation between Explorer and Internet Explorer.
Raymond asks for this other browser object because he needs to call IShellBrowser::QueryActiveShellView
to gain access to the shell view and the world of IShellFolder
s and PIDLs.
You can think of IShellBrowser
as the host/container of IWebBrowser
and/or IShellView
but keep in mind that IShellView
can be implemented by 3rd-parties when you are in special namespace folders and IShellBrowser
can be implemented by 3rd-party file explorer applications so you can't really say that IWebBrowser
and the other parts of a Explorer window are tightly connected.
When QueryService
does not know the service you are asking for, it is allowed to ask its client-site/host/"parent"/"child". If you want to get the "main" view instance you ask for SID_STopLevelBrowser
. Similarly, you can ask the top level browser for SID_SShellBrowser
to get the current tab in IE7+.

- 97,548
- 12
- 110
- 164