-
May 8th, 2007, 09:12 AM
#1
IHTMLDocument2 load from memory
Greetings...
I'm trying to load HTML from memory into the IHTMLDocument2:
(OnInitDialog)
Code:
InfoStr = "<html><body><h1>test</h1></body></html>";
CComVariant address("about:blank");
internetExplorer.Navigate2(&address, NULL, NULL, NULL, NULL);
LPDISPATCH documentDispatch = internetExplorer.get_Document();
if (documentDispatch)
{
CComPtr<IHTMLDocument2> document;
if (SUCCEEDED(documentDispatch->QueryInterface(__uuidof(IHTMLDocument2), (void**)&document)) && document)
{
CComPtr<IPersistStreamInit> persistStreamInit;
if (SUCCEEDED(document->QueryInterface(__uuidof(IPersistStreamInit), (void**)&persistStreamInit)) && persistStreamInit)
{
if (SUCCEEDED(persistStreamInit->InitNew()))
{
TCHAR* memory = (TCHAR*)GlobalAlloc(GMEM_MOVEABLE, (InfoStr.GetLength() + 1)*sizeof(TCHAR));
if (memory)
{
_tcscpy(memory, InfoStr.GetBuffer());
memory[InfoStr.GetLength()] = 0;
CComPtr<IStream> stream;
if (CreateStreamOnHGlobal((HGLOBAL)memory, TRUE, &stream) == S_OK)
{
HRESULT result = persistStreamInit->Load(stream);
bool stop = true;
}
}
}
}
}
}
(internetExplorer -- created by "Insert ActiveX Control" from "Microsoft Web Browser")
persistStreamInit->Load returns S_OK, but internetExplorer shows an empty page.
What's wrong here?
Best regards...
-
May 8th, 2007, 09:59 AM
#2
Re: IHTMLDocument2 load from memory
Well try this
in your header
Code:
void DisplayDirect(CString sHtml);
HRESULT LoadHtmlFromStream(IStream* pStream);
Code:
void CHTMLDlg::DisplayDirect(CString sHtml)
{
HRESULT hr;
HGLOBAL hHTMLText;
IStream* pStream = NULL;
hHTMLText = GlobalAlloc( GPTR, sHtml.GetLength()+1 );
if (hHTMLText) {
lstrcpy((char*)hHTMLText, sHtml);
hr = CreateStreamOnHGlobal(hHTMLText, TRUE, &pStream );
if (SUCCEEDED(hr)) {
LoadHtmlFromStream(pStream);
pStream->Release();
}
}
}
HRESULT CHMTLDlg::LoadHtmlFromStream(IStream* pStream)
{
HRESULT hr;
IDispatch* pHtmlDoc = NULL;
IPersistStreamInit* pPersistStreamInit = NULL;
internetExplorer.Navigate( _T("about:blank"), NULL, NULL, NULL, NULL );
pHtmlDoc = internetExplorer.GetDocument(); // m_WebBrowser is your control
if (pHtmlDoc)
{
pHtmlDoc->QueryInterface( IID_IPersistStreamInit, (void**)&pPersistStreamInit );
pPersistStreamInit->InitNew();
pPersistStreamInit->Load( pStream );
pPersistStreamInit->Release();
}
return hr;
}
usage
Code:
DisplayDirect("<html><body><h1>test</h1></body></html>");
-
July 24th, 2007, 08:07 AM
#3
Re: IHTMLDocument2 load from memory
I have been studying how to use c++ to display HTML in a window. After looking at what msdn had, I found reliable samples at
1. http://www.adp-gmbh.ch/win/misc/mshtml/HTMLWindow.html and
2. http://www.codeproject.com/com/cwebpage.asp
The samples should privide some examples.
But can someone solve the problem below:
I compliled both codes and they work... but fails in other PCs.
Compliled in Window 2000 server on Vb. Net 2003.
Known PCs to work:
xp
Not working on:
Windows 2000 professional
I could not find other platforms to test.
When I trace HTMLWindow(René Nyffenegger) codes, it seems to fail at HTMLWindow.cpp/long HTMLWindow::HTML(std::string const& html_txt)/if (!lpDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&htmlDoc2))
So far I have not traced SimpleBrowserDemo(Jeff Glatt). But the compiled application seem to work where the above is working and vise-versa.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|