Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Big difference between VB new operator and COM CoCreateInstance?

Big difference between VB new operator and COM CoCreateInstance?

Scheduled Pinned Locked Moved COM
c++htmlcomdebuggingquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brigsoft
    wrote on last edited by
    #1

    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 "" CComBSTR SomeText("Some Text); hr = pBody->put_outerHTML((BSTR)SomeText); // ;-( falls 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? ================================ My products are here

    A 1 Reply Last reply
    0
    • B Brigsoft

      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 "" CComBSTR SomeText("Some Text); hr = pBody->put_outerHTML((BSTR)SomeText); // ;-( falls 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? ================================ My products are here

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      Sorry don't have time to check it myself, but should work: you can try to query for IPersistStreamInit, and then call IPersistStreamInit::InitNew, that should initialize the html document object Edward

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups