-
February 20th, 2013, 06:02 PM
#1
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.
-
February 21st, 2013, 09:41 AM
#2
Re: Extracting Stuff from an IHTMLDocument2 in C++ ?
Best regards,
Igor
-
February 21st, 2013, 11:11 AM
#3
Re: Extracting Stuff from an IHTMLDocument2 in C++ ?
Originally Posted by endemoniada
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|