Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IMarkupServices::ParseString Memory leakage

29 views
Skip to first unread message

Jigu

unread,
May 20, 2009, 6:33:08 AM5/20/09
to
Dear Friends,

I am using IMarkUpServices::ParseString to parse HTML data to plain
text.

I am using VC++ 6.0 for development.

Nature of my application is Multithreaded.

MainThread()
{
for (int i =0<100;i++)
{
CString sHTMLData = "<p>hello world ! </p>",sPlaintext;
ConvertHTMLToText(sHTMLData, sPlaintext)
}
}

bool ConvertHTMLToText(const CString &sHTMLData, CString &sPlaintext)
{
HRESULT hr = S_OK;

try
{

///////////////////////////////////////////////////////////////////
hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
if( FAILED( hr ) ) { throw __LINE__; }

///////////////////////////////////////////////////////////////////
// Create a Document to bootstrap the process
CComPtr< MSHTML::IHTMLDocument2 > pDocument;
CoCreateInstance( CLSID_HTMLDocument, NULL,
CLSCTX_INPROC_SERVER, IID_IHTMLDocument2,
reinterpret_cast<PVOID*>( &pDocument ) );
if( NULL == pDocument.p ) { throw __LINE__; }

///////////////////////////////////////////////////////////////////
CComPtr< IPersistStreamInit > pPersistStream;
hr = pDocument->QueryInterface( IID_IPersistStreamInit,
reinterpret_cast<PVOID*>( &pPersistStream ) );
if( FAILED( hr ) ) { throw __LINE__; }

///////////////////////////////////////////////////////////////////
// From MSDN
hr = pPersistStream->InitNew();
if( FAILED( hr ) ) { throw __LINE__; }

///////////////////////////////////////////////////////////////////
CComPtr< MSHTML::IMarkupServices > pMarkupServices;
hr = pDocument->QueryInterface(__uuidof(IMarkupServices),
reinterpret_cast<PVOID*>( &pMarkupServices ) ) ;
if( FAILED( hr ) ) { throw __LINE__; }

///////////////////////////////////////////////////////////////////
CComPtr< MSHTML::IMarkupPointer > pBegin;

hr = pMarkupServices->CreateMarkupPointer( &pBegin );
if( FAILED( hr ) ) { throw __LINE__; }

///////////////////////////////////////////////////////////////////
CComPtr< MSHTML::IMarkupPointer > pEnd;
hr = pMarkupServices->CreateMarkupPointer( &pEnd );
if( FAILED( hr ) ) { throw __LINE__; }

///////////////////////////////////////////////////////////////////
CComPtr< MSHTML::IMarkupContainer > pContainer;

_bstr_t bsHTMLData(sHTMLData);

hr = pMarkupServices->ParseString(bsHTMLData, 0, &pContainer,
pBegin, pEnd );
if( FAILED( hr ) ) { throw __LINE__; }

///////////////////////////////////////////////////////////////////
CComPtr< MSHTML::IHTMLDocument2 > pNewDocument;
pContainer->QueryInterface( IID_IHTMLDocument,
reinterpret_cast<PVOID*>( &pNewDocument ) );
if( FAILED( hr ) ) { throw __LINE__; }

///////////////////////////////////////////////////////////////////
CComPtr< MSHTML::IHTMLElement> pBody;
hr = pNewDocument->get_body( &pBody);
if( FAILED( hr ) ) { throw __LINE__; }

CComBSTR Text;
hr = pBody->get_innerText( &Text );

sPlainText = Text.m_str;

}

catch( _com_error* e )
{
std::wcout << std::endl;
std::wcout << L"COM Error: " << e->ErrorMessage() <<
std::endl;
std::wcout << std::hex << L" 0x" << std::setw( 8 ) << e-
>Error();
std::wcout << L" (Win32: " << std::dec << HRESULT_CODE(e-
>Error
() );
std::wcout << L")" << std::endl;

}

catch( INT line )
{

std::wcout << std::endl;
std::wcout << L"COM Error near Line " << line << std::endl;
std::wcout << std::hex << L" 0x" << std::setw( 8 ) << hr;
std::wcout << L" (Win32: " << std::dec << HRESULT_CODE( hr );
std::wcout << L")" << std::endl;

}

catch( ... )
{

std::wcout << std::endl;
std::wcout << L"COM Error:" << std::endl;
std::wcout << std::hex << L" 0x" << std::setw( 8 );
std::wcout << std::setfill( L'0' ) << hr;
std::wcout << L" (Win32: " << std::dec << HRESULT_CODE( hr );
std::wcout << L")" << std::endl;

}

CoUninitialize( );

return HRESULT_CODE( hr );
}

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Now when i pass string of different lenght and different content in it
then memory leakage comes into picture.

Please suggest some solution to work around .

Regards,

Jignesh

0 new messages