Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我必须使用->;释放()? 我正在用C++上的WebBubor主机工作,我成功地处理了事件,我在DeSDIDOBoOfftoFruts:< /P>上运行这个空洞 void DocumentComplete(LPDISPATCH pDisp, VARIANT *url) { READYSTATE rState; iBrowser->get_ReadyState(&rState); if(rState == READYSTATE_COMPLETE) { HRESULT hr; IDispatch *pHtmlDoc = NULL; IHTMLDocument2 *pDocument = NULL; IHTMLElement *pBody = NULL; IHTMLElement *lpParentElm = NULL; BSTR bstrHTMLText; hr = iBrowser->get_Document(&pHtmlDoc); hr = pHtmlDoc->QueryInterface(IID_IHTMLDocument2, (void**)&pDocument); if( (FAILED(hr)) || !pDocument) { MessageBox(NULL, "QueryInterface failed", "WebBrowser", MB_OK); } hr = pDocument->get_body( &pBody ); if( (!SUCCEEDED(hr)) || !pBody) { MessageBox(NULL, "get_body failed", "WebBrowser", MB_OK); } pBody->get_parentElement(&lpParentElm); lpParentElm->get_outerHTML(&bstrHTMLText); _bstr_t bstr_t(bstrHTMLText); std::string sTemp(bstr_t); MessageBox(NULL, sTemp.c_str(), "WebBrowser", MB_OK); } } 我不太喜欢C++,我是通过在谷歌中查看其他代码来构建这个代码的。现在我知道我必须使用->发布,但我必须使用所有这些吗 pHtmlDoc->Release(); pDocument->Release(); pBody->Release(); lpParentElm->Release(); iBrowser->Release();_C++_Visual Studio 2010_Visual C++_Memory Management - Fatal编程技术网 发布,但我必须使用所有这些吗 pHtmlDoc->Release(); pDocument->Release(); pBody->Release(); lpParentElm->Release(); iBrowser->Release();,c++,visual-studio-2010,visual-c++,memory-management,C++,Visual Studio 2010,Visual C++,Memory Management" /> 发布,但我必须使用所有这些吗 pHtmlDoc->Release(); pDocument->Release(); pBody->Release(); lpParentElm->Release(); iBrowser->Release();,c++,visual-studio-2010,visual-c++,memory-management,C++,Visual Studio 2010,Visual C++,Memory Management" />

我必须使用->;释放()? 我正在用C++上的WebBubor主机工作,我成功地处理了事件,我在DeSDIDOBoOfftoFruts:< /P>上运行这个空洞 void DocumentComplete(LPDISPATCH pDisp, VARIANT *url) { READYSTATE rState; iBrowser->get_ReadyState(&rState); if(rState == READYSTATE_COMPLETE) { HRESULT hr; IDispatch *pHtmlDoc = NULL; IHTMLDocument2 *pDocument = NULL; IHTMLElement *pBody = NULL; IHTMLElement *lpParentElm = NULL; BSTR bstrHTMLText; hr = iBrowser->get_Document(&pHtmlDoc); hr = pHtmlDoc->QueryInterface(IID_IHTMLDocument2, (void**)&pDocument); if( (FAILED(hr)) || !pDocument) { MessageBox(NULL, "QueryInterface failed", "WebBrowser", MB_OK); } hr = pDocument->get_body( &pBody ); if( (!SUCCEEDED(hr)) || !pBody) { MessageBox(NULL, "get_body failed", "WebBrowser", MB_OK); } pBody->get_parentElement(&lpParentElm); lpParentElm->get_outerHTML(&bstrHTMLText); _bstr_t bstr_t(bstrHTMLText); std::string sTemp(bstr_t); MessageBox(NULL, sTemp.c_str(), "WebBrowser", MB_OK); } } 我不太喜欢C++,我是通过在谷歌中查看其他代码来构建这个代码的。现在我知道我必须使用->发布,但我必须使用所有这些吗 pHtmlDoc->Release(); pDocument->Release(); pBody->Release(); lpParentElm->Release(); iBrowser->Release();

我必须使用->;释放()? 我正在用C++上的WebBubor主机工作,我成功地处理了事件,我在DeSDIDOBoOfftoFruts:< /P>上运行这个空洞 void DocumentComplete(LPDISPATCH pDisp, VARIANT *url) { READYSTATE rState; iBrowser->get_ReadyState(&rState); if(rState == READYSTATE_COMPLETE) { HRESULT hr; IDispatch *pHtmlDoc = NULL; IHTMLDocument2 *pDocument = NULL; IHTMLElement *pBody = NULL; IHTMLElement *lpParentElm = NULL; BSTR bstrHTMLText; hr = iBrowser->get_Document(&pHtmlDoc); hr = pHtmlDoc->QueryInterface(IID_IHTMLDocument2, (void**)&pDocument); if( (FAILED(hr)) || !pDocument) { MessageBox(NULL, "QueryInterface failed", "WebBrowser", MB_OK); } hr = pDocument->get_body( &pBody ); if( (!SUCCEEDED(hr)) || !pBody) { MessageBox(NULL, "get_body failed", "WebBrowser", MB_OK); } pBody->get_parentElement(&lpParentElm); lpParentElm->get_outerHTML(&bstrHTMLText); _bstr_t bstr_t(bstrHTMLText); std::string sTemp(bstr_t); MessageBox(NULL, sTemp.c_str(), "WebBrowser", MB_OK); } } 我不太喜欢C++,我是通过在谷歌中查看其他代码来构建这个代码的。现在我知道我必须使用->发布,但我必须使用所有这些吗 pHtmlDoc->Release(); pDocument->Release(); pBody->Release(); lpParentElm->Release(); iBrowser->Release();,c++,visual-studio-2010,visual-c++,memory-management,C++,Visual Studio 2010,Visual C++,Memory Management,因为在我用来构建代码的示例中,它只将其用于ihtmlement。是的,您必须在这些指针上调用Release(),否则对象将泄漏。这同样适用于BSTR 如果您为此使用智能指针-ATL::CComPtr/ATL::CComBSTR或\u com\u ptr\t/\u bstr\u t是的,您必须在这些指针上调用Release(),否则对象将泄漏。这同样适用于BSTR 如果您使用智能指针来实现这一点-ATL::CComPtr/ATL::CComBSTR或\u com\u ptr\t/\u bstr\t

因为在我用来构建代码的示例中,它只将其用于ihtmlement。

是的,您必须在这些指针上调用
Release()
,否则对象将泄漏。这同样适用于BSTR


如果您为此使用智能指针-
ATL::CComPtr
/
ATL::CComBSTR
\u com\u ptr\t
/
\u bstr\u t
是的,您必须在这些指针上调用
Release()
,否则对象将泄漏。这同样适用于BSTR


如果您使用智能指针来实现这一点-
ATL::CComPtr
/
ATL::CComBSTR
\u com\u ptr\t
/
\u bstr\t
,您应该将这些对象包装到
CComPtr
或其变体中。这将为您处理释放。它与RAII的概念一致。

您应该将这些对象包装到
CComPtr
或其变体中。这将为您处理释放。它符合RAII的概念。

是的,你有。但不是在iBrowser上,您没有在代码中获得指针


请注意,错误检查是不够的,当get_Document()失败时,代码会爆炸。get_parentElement()也一样。在消息框被解除后。

是的,您可以这样做。但不是在iBrowser上,您没有在代码中获得指针


请注意,错误检查是不够的,当get_Document()失败时,代码会爆炸。get_parentElement()也一样。在消息框被解除后。

您不想释放
iBrowser
,除非这是您最后要做的事情-
iBrowser
不在此函数的范围内。我需要包含atlbase.h才能使用CComPtr,对吗?这是否会使我编译的应用程序有一些额外的dll依赖项或类似的东西?@jarkam:如果你只使用
CComPtr
,你就不会有额外的依赖项-类是模板化的,因此你会将代码静态链接到可执行文件中。你不想释放
iBrowser
,除非这是您最后要做的事情-
iBrowser
超出了此函数的范围。我需要包含atlbase.h才能使用CComPtr,对吗?这是否会使我编译的应用程序有一些额外的dll依赖项或类似的东西?@jarkam:如果你只使用
CComPtr
,你将不会有额外的依赖项-类是模板化的,因此你将代码静态链接到可执行文件中。