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. ATL / WTL / STL
  4. BHO reading HTML input value

BHO reading HTML input value

Scheduled Pinned Locked Moved ATL / WTL / STL
c++htmlhelpquestionannouncement
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.
  • M Offline
    M Offline
    macattack
    wrote on last edited by
    #1

    I am trying to read an html page and retrieve the value of three hidden input fields sure as: VC++6.0/ATL/BHO -- Below is the code I am working with to read in the value (1500) but it is not working. I think i am missing something. HRESULT hr; TCHAR sPort[25]; IDispatch* pElemDisp = NULL; IHTMLInputHiddenElement* pElem = NULL; IHTMLElementCollection *pElemcoll; // Get the WebBrowser's document object CComPtr pDisp; HRESULT hr = m_spWebBrowser2->get_Document(&pDisp); if (FAILED(hr)) return false; CComQIPtr spHTML; spHTML = pDisp; _variant_t tagName("input"); _variant_t tagNamePort("port"); BSTR* pValuePort = NULL; spHTML->get_forms(&pElemcoll); hr = pElemColl->tags( tagName, &pElemDisp ); if ( SUCCEEDED(hr) ) { hr = pElemDisp->QueryInterface( IID_IHTMLInputHiddenElement, (void**)&pElem ); if ( SUCCEEDED(hr) ) { hr = pElem->get_value(pValuePort); if ( SUCCEEDED(hr) ) { //Set port _stprintf(sPort, _T("%s"), (LPCTSTR)pValuePort); m_sPort = (int)sPort; } pElem->Release(); } pElemDisp->Release(); } //at this point m_sPort is NULL not 1500 :-( I think I may not be handling the Element Collection object correctly. Any pointers as to where i am going wrong? Thank you for any help you can give..

    M 1 Reply Last reply
    0
    • M macattack

      I am trying to read an html page and retrieve the value of three hidden input fields sure as: VC++6.0/ATL/BHO -- Below is the code I am working with to read in the value (1500) but it is not working. I think i am missing something. HRESULT hr; TCHAR sPort[25]; IDispatch* pElemDisp = NULL; IHTMLInputHiddenElement* pElem = NULL; IHTMLElementCollection *pElemcoll; // Get the WebBrowser's document object CComPtr pDisp; HRESULT hr = m_spWebBrowser2->get_Document(&pDisp); if (FAILED(hr)) return false; CComQIPtr spHTML; spHTML = pDisp; _variant_t tagName("input"); _variant_t tagNamePort("port"); BSTR* pValuePort = NULL; spHTML->get_forms(&pElemcoll); hr = pElemColl->tags( tagName, &pElemDisp ); if ( SUCCEEDED(hr) ) { hr = pElemDisp->QueryInterface( IID_IHTMLInputHiddenElement, (void**)&pElem ); if ( SUCCEEDED(hr) ) { hr = pElem->get_value(pValuePort); if ( SUCCEEDED(hr) ) { //Set port _stprintf(sPort, _T("%s"), (LPCTSTR)pValuePort); m_sPort = (int)sPort; } pElem->Release(); } pElemDisp->Release(); } //at this point m_sPort is NULL not 1500 :-( I think I may not be handling the Element Collection object correctly. Any pointers as to where i am going wrong? Thank you for any help you can give..

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Have you stepped through with the debugger? Which line in there is failing? If you just look at m_sPort after it's done, you can't tell which call fails. Once you figure that part out, you need to fix your string handling. You don't pass a BSTR* to get_value(), you pass the address of a BSTR so that get_value() can store the return value in it:

      BSTR bsValuePort = NULL;

      hr = pElem->get_value ( &bsValuePort );
      // ... use bsValuePort ...

      // Don't forget to free the string:
      SysFreeString ( bsValuePort );

      Then, casting a BSTR to a LPCTSTR will do you no good in an ANSI build. Nor will casting a char array to an int. Assuming m_sPort is a CString, You can just write:

      m_sPort = (LPCWSTR) bsValuePort;

      and let the CString constructor do the conversion. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ You cannot stop me with paramecium alone!

      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