0

I am using slightly modified IDocHostUIHandler from https://stackoverflow.com/a/21699086/592212 in simple one main window test application with only WPF WebBrowser component in that Window. The initialization code is as follows:

    public MainWindow()
    {
        InitializeComponent();

        _wbHostHandler = new WebBrowserHostUIHandler(PART_WebBrowser);
        _wbHostHandler.Flags |= HostUIFlags.DpiAware;

        PART_WebBrowser.Navigate("SOME_URL");
    }

There is really nothing else going on in the Application. Still, after running the application, an error is thrown in COM component (therefore, I can not use a debugger to trap it) and 0xc0000409 (STATUS_STACK_BUFFER_OVERRUN) is reported in Event Viewer.

Any ideas of what is causing the error or how to get rid of it?

(Win10 Pro 1703 (build 15063.483) and .NET 4.6.2)

Source Code: https://www.dropbox.com/s/ddob6p7jh4dfsda/UIHostCrashDemo.zip?dl=1

Miro Hudak
  • 2,155
  • 2
  • 21
  • 29
  • Well, that low-voted solution ought to start looking a lot more attractive :) – Hans Passant Aug 05 '17 at 21:31
  • @HansPassant Which solution do you mean exactly? – Miro Hudak Aug 05 '17 at 21:54
  • Mine, the one on the bottom in the linked Q+A. Code used by hundreds of thousands of programmers always has less wonky problems. – Hans Passant Aug 05 '17 at 23:18
  • I don't reproduce the problem. Do you have a full reproducing project? Note it may be related to IE plugins/addons, etc. that don't expect that context. – Simon Mourier Aug 06 '17 at 06:08
  • @HansPassant I thought so. But the problem is, I was not solving the problem with context menu, but with high-dpi support in embedded web browser; solved it at the end by using already obsoleted 96DPI feature, but I wanted to figure out, why this one was crashing. As for your before-mentioned answer, it's unfortunately brief to the extend of being unclear of what you wanted to say with it. – Miro Hudak Aug 06 '17 at 07:09
  • @SimonMourier Interesting; then it might be linked to the web site it is displaying as well. I can not share it directly, but I will try to distill it to the essence and create a test case. – Miro Hudak Aug 06 '17 at 07:12
  • @SimonMourier See original post for link to source code. – Miro Hudak Aug 06 '17 at 10:59

1 Answers1

2

I don't know where you got your WebBrowserHostUIHandler.cs content from but it's wrong. The definition of IDocHostUIHandler simply misses the TranslateAccelerator method.

I guess it's because my initial code used System.Windows.Forms.Message type which is a reference to the System.Windows.Forms (winforms) assembly. If this is such a problem, the method can just be replaced by this if the message is not used (wich is the case in my initial code).

So in the interface you must add this, just after ResizeBorder:

[PreserveSig]
uint TranslateAccelerator(IntPtr msg, ref Guid group, int nCmdID);

And you must implement it anywhere in the code, like this:

uint Native.IDocHostUIHandler.TranslateAccelerator(IntPtr msg, ref Guid group, int nCmdID)
{
    return S_FALSE;
}

But again, this is optional, if you want something that works just carefully copy/paste my code from my post and add a reference to System.Windows.Forms if needed.

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • 1
    Thank you for your answer. The funny thing is, that is your code in that example, but I have no idea, how it ended up missing that method from interface. Otherwise, it is the same, and only coding style is changed to fit the rest of my code. Still, while this is an answer to my original problem (it is not crashing anymore), it does not solve my problem, as the High DPI support is a mess and while rendering in proper size, it does not render correctly at all. So I have to stick with obsoleted-but-working in last IE version in Win10, `FEATURE_96DPI_PIXEL`. – Miro Hudak Aug 08 '17 at 10:09