microsoft/Windows-classic-samples

CloudMirror-Sample - Retrieval of Explorer window handle not applicable

AliveDevil opened this issue · 1 comments

HWND hwnd = nullptr;
if (_site)
{
// Get the HWND of the browser from the site to parent our message box to
winrt::com_ptr<IUnknown> browser;
winrt::check_hresult(IUnknown_QueryService(_site.get(), SID_STopLevelBrowser, __uuidof(browser), browser.put_void()));
IUnknown_GetWindow(browser.get(), &hwnd);
}

Running this code and step-debugging into it you'll see that HWND always returns NULL. There cannot be any value attached to it, due to RPC_E_CANTCALLOUT_ININPUTSYNCCALL (0x8001010D).

The underlying method of getting the HWND shows why this is the case:

HWND hwnd = nullptr;

if (_site)
{
    // Get the HWND of the browser from the site to parent our message box to
    winrt::com_ptr<IShellBrowser> browser;
    winrt::check_hresult(IUnknown_QueryService(_site.get(), SID_STopLevelBrowser, IID_PPV_ARGS(browser.put())));
    winrt::check_hresult(browser->GetWindow(&hwnd));
}

//Added: In fact, using winrt::check_hresult(IUnknown_GetWindow(…)) returns the exact same error.

Yeah, it turns out this doesn't work. The code has been removed in the most recent update.