怎么获得IWebBrowser2的Internet Explorer_Server窗口句柄

如何获得IWebBrowser2的Internet Explorer_Server窗口句柄
我们知道WebBrowser控件窗口是这样的:

--Shell Embedding
 |-Shell DocObject View
  |--Internet Explorer_Server

现在想获得Internet Explorer_Server窗口的句柄

原本想直接用IWebBrowser2的get_HWND方法来获取,结果失败并得到返回值0x80004005。

后来找到这篇文章http://support.microsoft.com/kb/244310,说是要通过IOleWindow来获取。

实验发现这种方法确实能得到Shell Embedding的窗口句柄,但随后试图通过GetWindow(hwnd, GW_CHILD)或者是FindWindowEx函数从Shell Embedding句柄来得到Internet Explorer_Server甚至是Shell DocObject View窗口句柄都会遭遇失败(返回值为NULL),更加令人匪夷所思的是用GetLastError得到的错误代码居然为0。使用管理员权限也无效

网上有说法说这可能是新版ie的保护模式搞的鬼(我现在正在使用IE9 + Win7 64位)。不知道有没有什么解决办法。
------解决思路----------------------
我也刚写了一个,你用吧

#include <ShlGuid.h>

HWND GetHwndFromIWebBrowser2(IWebBrowser2* pWebBrowser2)
{
if (pWebBrowser2 == NULL)
return NULL;
IServiceProvider* pServiceProvider = NULL;
//1. --Shell Embedding
if (SUCCEEDED(pWebBrowser2->QueryInterface(
IID_IServiceProvider, 
(void**)&pServiceProvider)))
{
IOleWindow* pWindow = NULL;
if (SUCCEEDED(pServiceProvider->QueryService(
SID_SShellBrowser, 
IID_IOleWindow,
(void**)&pWindow)))
{
HWND hwndBrowser = NULL;
if (SUCCEEDED(pWindow->GetWindow(&hwndBrowser)))
{
//2.
------解决思路----------------------
-Shell DocObject View
HWND hchildwnd = GetWindow(hwndBrowser, GW_CHILD);
while (hchildwnd)
{
TCHAR wndname[MAX_PATH] = _T("");
GetClassName(hchildwnd, wndname, MAX_PATH);
if ( wcscmp(wndname,_T("Shell DocObject View")) == 0 )
{
//3.
------解决思路----------------------
--Internet Explorer_Server   
HWND hiewnd = GetWindow(hchildwnd, GW_CHILD);
while (hiewnd)
{
TCHAR wndname[MAX_PATH] = _T("");
GetClassName(hiewnd, wndname, MAX_PATH);
if ( wcscmp(wndname,_T("Internet Explorer_Server")) == 0 )
{
return hiewnd;
}
hiewnd = GetNextWindow(hiewnd, GW_HWNDNEXT);
}
return hwndBrowser;
}
hchildwnd = GetNextWindow(hchildwnd, GW_HWNDNEXT);
}
return hwndBrowser;
}

pWindow->Release();
}

pServiceProvider->Release();

return NULL;
}