locked
WinRT W8 Create WebView in C++ and add it to the main view RRS feed

  • Question

  • I'm currently trying to display a webview in a WinRT application (without c#). First, is it possible ?

    I'm currently trying to do it that way:

    Windows::UI::Xaml::Controls::WebView^ webView = ref new Windows::UI::Xaml::Controls::WebView();
    webView->NavigateToString("http://www.google.com");

    But as I want this code to be run in the main thread (I think, to create a UI element it's compulsory) I'm running it like that:

    Windows::ApplicationModel::Core::CoreApplication::MainView->CoreWindow->GetForCurrentThread()->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler(
        []
        {
            Windows::UI::Xaml::Controls::WebView^ webView = ref new Windows::UI::Xaml::Controls::WebView();
            webView->NavigateToString("http://www.google.com");
        }
    ));

    Bad point is that this line:

    webView->NavigateToString("http://www.google.com");

    Is never reached. In the output console I have three exceptions raised (while debugging step by step) at that line:

    Windows::UI::Xaml::Controls::WebView^ webView = ref new Windows::UI::Xaml::Controls::WebView();

    The exceptions raised are the following:

    First-chance exception at 0x763B4B32 in Direct3DApp1.exe: Microsoft C++ exception: Platform::WrongThreadException ^ at memory location 0x0320EFE4. HRESULT:0x8001010E
    First-chance exception at 0x763B4B32 in Direct3DApp1.exe: Microsoft C++ exception: Platform::WrongThreadException ^ at memory location 0x0320EFE4. HRESULT:0x8001010E
    First-chance exception at 0x763B4B32 (KernelBase.dll) in Direct3DApp1.exe: 0x40080201: WinRT originate error (parameters: 0x8001010E, 0x00000051, 0x0320E494).

    If you have any idea how to create a webview and display it in a C++ only application on Windows 8 (not Windows Phone 8), it would be great. Meanwhile I'm strongly thinking about integrating webkit in my application if it could help me to display a webkit webview in C++ only.

    Thx

    Thursday, November 7, 2013 1:59 PM

All replies

  • The first thing that jumps out is that you're not adding the WebView to your visual tree. After creating it you need to add it to a container on your page. See http://msdn.microsoft.com/en-us/library/windows/apps/hh825871.aspx for more on using Xaml in a D3D app.

    Beyond that your code looks superficially correct.

    --Rob

    Thursday, November 7, 2013 4:03 PM
    Moderator
  • Hello,

    Thx for your insight, but my main probleme is that it crash in that line:

     Windows::UI::Xaml::Controls::WebView^ webView = ref new Windows::UI::Xaml::Controls::WebView();

    Which prevent me for going any further and add it in the treeview.

    :s

    Thursday, November 7, 2013 4:39 PM