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. C / C++ / MFC
  4. CComPtr and CDHtmlDialog

CComPtr and CDHtmlDialog

Scheduled Pinned Locked Moved C / C++ / MFC
question
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.
  • G Offline
    G Offline
    George L Jackson
    wrote on last edited by
    #1

    I have created a CDHtmlDialog base application and I want to create IHTMLOptionElement from an external source into an IHTMLSelectElement. I have managed to do this. However, I am not sure if my code will leak: // SelectID is already empty CComPtr pSelect; HRESULT hr = GetElementInterface(_T("SelectID"), &pSelect); if (FAILED(hr)) return; CComPtr pWindow; hr = m_spHtmlDoc->get_parentWindow(&pWindow); if (FAILED(hr)) return; CComPtr pOptionFactory; hr = pWindow->get_Option(&pOptionFactory); if (FAILED(hr)) return; while (Source.MoveNext()) { CComPtr pOption; hr = pOptionFactory->create(CComVariant(Source.Col(0), Source.Col(1), CComVariant(VARIANT_FALSE), CComVariant(VARIANT_FALSE), &pOption); if (FAILED(hr)) return; CComPtr pElement; pElement = pOption; // This works but what is it doing? // IHTMLSelectElement::add(IHTMLElement*, VARIANT); hr = pSelect->add(pElement, CComVariant(-1)); // This works! if (FAILED(hr)) return; } Is the code "pElement = pOption;" used correctly above? Geo

    D 1 Reply Last reply
    0
    • G George L Jackson

      I have created a CDHtmlDialog base application and I want to create IHTMLOptionElement from an external source into an IHTMLSelectElement. I have managed to do this. However, I am not sure if my code will leak: // SelectID is already empty CComPtr pSelect; HRESULT hr = GetElementInterface(_T("SelectID"), &pSelect); if (FAILED(hr)) return; CComPtr pWindow; hr = m_spHtmlDoc->get_parentWindow(&pWindow); if (FAILED(hr)) return; CComPtr pOptionFactory; hr = pWindow->get_Option(&pOptionFactory); if (FAILED(hr)) return; while (Source.MoveNext()) { CComPtr pOption; hr = pOptionFactory->create(CComVariant(Source.Col(0), Source.Col(1), CComVariant(VARIANT_FALSE), CComVariant(VARIANT_FALSE), &pOption); if (FAILED(hr)) return; CComPtr pElement; pElement = pOption; // This works but what is it doing? // IHTMLSelectElement::add(IHTMLElement*, VARIANT); hr = pSelect->add(pElement, CComVariant(-1)); // This works! if (FAILED(hr)) return; } Is the code "pElement = pOption;" used correctly above? Geo

      D Offline
      D Offline
      Diddy
      wrote on last edited by
      #2

      Thats fine. The assignment operator for CComPtr will call AddRef for you, or in this case take an assigment from the underyling IUnknown of pOption and do a QueryInterface on it for you - which in tern does the AddRef. When using the assingment operators you should always check the assinged pointer for NULL as this is the only way CCom(QI)Ptr has to report any failure code for you - unlike when you call QI manually and you get your HRESULT back

      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