Extracting Stuff from an IHTMLDocument2 in C++ ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Extracting Stuff from an IHTMLDocument2 in C++ ?

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Posts
    14

    Extracting Stuff from an IHTMLDocument2 in C++ ?

    Hi guys,

    I got as far as getting a web page into an IHTMLDocument2 but I don't know what to do from there, all the examples I found are C# or .NET or something else I don't understand.

    Will someone please give me a simple example in C++ of getting all the links from an IHTMLDocument2 ?

    I was able to do this:

    Code:
    IHTMLElementCollection* collection;
    hResult=document->get_links(&collection);
    long nLinks;
    collection->get_length(&nLinks); // returns correct number
    collection->Release();
    How do I loop through the collection and extract the actual links ? Also, if they come out as BSTR do I simple treat them as WCHAR* ? If I can do that I can figure out the rest myself.

    Thanks a lot.

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,877

    Re: Extracting Stuff from an IHTMLDocument2 in C++ ?

    Best regards,
    Igor

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,639

    Re: Extracting Stuff from an IHTMLDocument2 in C++ ?

    Quote Originally Posted by endemoniada View Post
    How do I loop through the collection and extract the actual links ? Also, if they come out as BSTR do I simple treat them as WCHAR* ? If I can do that I can figure out the rest myself.
    1) you can use get_links() or you can also use the more generic getElementsByTagName or getElementsByName (requires IHtmlDocument3)
    As said by Igor... Use the item() member to iterate the element collection.

    2) a BSTR is not a WCHAR*
    Used correctly you can 'sometimes' treat a BSTR as a const WCHAR* in your own code without defect (such as passing it to a Win API function).
    The reverse will likely not work, and could crash your app. (casting a WCHAR* to a BSTR is a nono)

    If you're using MFC/ATL. You can use CComBSTR in lieu of a BSTR, the CComBSTR will have a lot of behaviour similarities to MFC's CString (or CStringW to be more precise). The advantage of CComBSTR over plain BSTR is automatic creation/cleanup.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center