佚名通过本文主要向大家介绍了parentwindow,pb parentwindow,多线程批量getshell,get.cell函数怎么用,getvalue函数等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: get_parentWindow 这个函数是不是不能跨线程使用?
描述:
这段代码在BHO中运行是没问题的, 现在的运行环境是一个单独的外部控制台程序, 在 spIHTMLDocument2->get_parentWindow(&spIHTMLWindow2); 这句会直接崩溃
MSDN 帮助上没写, http://msdn.microsoft.com/en-us/library/aa752599%28v=vs.85%29.aspx, 但是下面别人写到
InvalidCastException Edit
Keep in mind: this property can be used only from the thread where document was created, otherwise you will get InvalidCastException.
可能真的如别人说的一样,不能在非document 创建者的线程里运行, 不知道是否还有别的解决方案. 谢谢
描述:
CComPtr<IShellWindows> spShellWin;
HRESULT hr = spShellWin.CoCreateInstance( CLSID_ShellWindows );
if (FAILED(hr)) return;
long nCount = 0;
spShellWin->get_Count(&nCount);
for (int i= 0; i < nCount; i++)
{
CComPtr<IDispatch> spDisp;
hr = spShellWin->Item(CComVariant(i), &spDisp );
if (FAILED(hr)) continue;
CComQIPtr<IWebBrowser2> spBrowser = spDisp;
if (!spBrowser) continue;
WCHAR *Url;
hr = spBrowser->get_LocationURL(&Url);
if ( FAILED( hr ) ) continue;
string sUrl = WCharToChar((LPCWSTR)Url);
CComQIPtr<IHTMLDocument2> spDoc;
hr = spBrowser->get_Document((IDispatch **) &spDoc );
if ( FAILED ( hr ) ) continue;
CComPtr <IHTMLDocument2> spIHTMLDocument2;
if (spBrowser && SUCCEEDED(spBrowser->get_Document((IDispatch **)&spIHTMLDocument2)))
{
CComPtr <IHTMLWindow2> spIHTMLWindow2;
spIHTMLDocument2->get_parentWindow(&spIHTMLWindow2);
}
这段代码在BHO中运行是没问题的, 现在的运行环境是一个单独的外部控制台程序, 在 spIHTMLDocument2->get_parentWindow(&spIHTMLWindow2); 这句会直接崩溃
MSDN 帮助上没写, http://msdn.microsoft.com/en-us/library/aa752599%28v=vs.85%29.aspx, 但是下面别人写到
InvalidCastException Edit
Keep in mind: this property can be used only from the thread where document was created, otherwise you will get InvalidCastException.
可能真的如别人说的一样,不能在非document 创建者的线程里运行, 不知道是否还有别的解决方案. 谢谢