Click to See Complete Forum and Search --> : Big difference between VB new operator and COM CoCreateInstance?


Alex Rest
January 15th, 2004, 03:34 PM
I want to convert HTML to TEXT from some string
It good works in VB code like this:


Dim body As String
Dim hd As HTMLDocument
Dim str As String

Set hd = New HTMLDocument


Open "c:\test\a.html" For Input As #1

body = Input(4188, #1)
hd.body.innerHTML = body
Debug.Print hd.body.outerText


I try do it with VC++ so:


IHTMLDocument2 *pHtmlDoc = NULL;
HRESULT hr;
hr = CoCreateInstance(CLSID_HTMLDocument,
NULL,
CLSCTX_INPROC_SERVER,
IID_IHTMLDocument2,
(LPVOID *) &pHtmlDoc);

IHTMLElement *pBody;
hr = pHtmlDoc->createElement(CComBSTR("BODY"), &pBody);

CComBSTR bsText;
hr = pBody->get_outerHTML(&bsText); // OK, we have "<BODY></BODY>"
CComBSTR SomeText("<BODY><b>Some Text</b></BODY>);
:mad: hr = pBody->put_outerHTML((BSTR)SomeText);


It falls down while "put_outerHTML"

Who know right solution?

PS
Set hd = New HTMLDocument
creates an object with html code with base document structure (5 tags: html, body, head, title, p).

CoCreateInstance creates absolutely empty object.

Why?

Thanks,
Alex

rxbagain
January 17th, 2004, 02:18 AM
What was the error value returned by calling CoCreateInstance? Maybe you just forgot to call OleInitialize/CoInitialize before calling CoCreateInstance.

Alex Rest
January 17th, 2004, 07:23 AM
It is a part of Outlook Plugin.
So Ole Init is OK.
All return codes are OK.
Most of get_ functions work.
The problem is put_ functions.
I cannot place the new text to the empty document.

Thanks,
Alex.