-3

I need to get the Url of the current page, I do it via get_LocationUrl, but first I need to find out, as the documentation says "is navigation complete", but I just don't understand how? Without using MFC or ATL.

adziri
  • 291
  • 3
  • 15
  • Please read [An introduction to COM connection points](https://blogs.msdn.microsoft.com/oldnewthing/20130611-00/?p=4113/), followed by [Dispatch interfaces as connection point interfaces](https://blogs.msdn.microsoft.com/oldnewthing/20130612-00/?p=4103/). Don't be surprised, COM is hard, events in COM are even harder. – IInspectable May 14 '18 at 17:19

1 Answers1

0

This is certainly far easier if you use MFC or ATL but it can be done without.

Create a type that implements IDispatch and that responds to at least DISPID_NavigateComplete, then register an instance of that type with the web browser control using the connection point mechanism (you would ask for the connection point for DWebBrowserEvents). Note that because DWebBrowserEvents is a dispinterface you do not have to implement all members, just return DISP_E_UNKNOWNNAME from GetIDsofNames for any non-implemented member.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
  • Thank you for the answer, but im not so good in winAPI, can u help me structurize my steps, so first i need to create some class, like `class CDispatch : public IDispatch { // and here override interface }` and what next? – adziri May 12 '18 at 16:16
  • @Azazel-San - yes, than call `QueryInterface` on `IWebBrowser2` for get `IConnectionPointContainer`. on it call `FindConnectionPoint` for `__uuidof(DWebBrowserEvents)` and on returned `IConnectionPoint` call `Advise` with pointer to your `DWebBrowserEvents` implementation – RbMm May 12 '18 at 16:20
  • What does it means, "that responds to at least DISPID_NavigateComplete", I can not fully understand. thank you in advance – adziri May 12 '18 at 16:22
  • @Azazel-San - this mean your `IDispatch::Invoke` implementation must respond to `DISPID_NAVIGATECOMPLETE` – RbMm May 12 '18 at 16:30
  • @RbMm maybe I did not understand something, but I do not see that IWebBrowser2 had the method QueryInterface its have IUnknown, i override QueryInterface in my class (i create embedded web browser), code takes here [link](https://www.codeproject.com/Tips/800585/Embedded-WebBrowser-IWebBrowser-in-Pure-Cplusplus) – adziri May 12 '18 at 16:30
  • @Azazel-San - `IWebBrowser2` of course have `QueryInterface`. all interfaces have this – RbMm May 12 '18 at 16:31
  • You can't hope to succeed without basic knowledge of COM. There are no shortcuts. Learn COM. – David Heffernan May 12 '18 at 16:39
  • @RbMm Indeed. I'm just stupid :) So, okey, I have class CDispatch, let's say I already override all interface methods, than i call QueryInterface on IWebBrowser2, so i need keep pointer on IWebBrowser2 to call it, in my CDispatch class, yes? And then, where I need call this QueryInterface? – adziri May 12 '18 at 16:40
  • Generally you would register the connection point just after creating the CLSID_WebBrowser object. – SoronelHaetir May 12 '18 at 17:32
  • Could you give any examples or books on the topic? Actually I'm interested in `IDispatch` automation (I don't understand how I have to integrate it into my project where I didn't use it) and about that how `"IDispatch::Invoke implementation must respond to DISPID_NAVIGATECOMPLETE"`. I searched on the Internet, however, somehow little information(( – adziri May 12 '18 at 20:42