WebViewProcessControl initialization crash

[亡魂溺海] 提交于 2019-12-11 07:19:32

问题


The Problem

I'm trying to use the "modern" web view API in my Win32 program, but when I initialize WebViewControlProcess, the program hangs for a couple of seconds, and then suddenly exits.

Minimal Example

// cl minimal.cpp /EHsc /std:c++17 /await windowsapp.lib

#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Web.UI.Interop.h>

using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::Web::UI::Interop;

int main(void) {
    winrt::init_apartment();
    printf("Hello\n");

    WebViewControlProcess webviews = WebViewControlProcess();

    printf("    world!\n");
}

Expected Output

Hello
    world!

Actual Output

Hello

Environment

I'm using Windows 10.0.17134 (1803).


回答1:


Turns out WebViewProcessControl needs you to winrt::init_apartment(apartment_type::single_threaded);. I don't know why it needs a single-threaded apartment, but it works.



来源:https://stackoverflow.com/questions/53754235/webviewprocesscontrol-initialization-crash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!