Last active
June 16, 2021 08:12
-
-
Save ADeltaX/d60a42a2034c9577f1498f7bfcf387c8 to your computer and use it in GitHub Desktop.
C++/WinRT snippet for creating or getting a DispatcherQueue (15063+)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <winrt/Windows.System.h> | |
winrt::Windows::System::DispatcherQueue CreateDispatcherQueue() | |
{ | |
auto coreMsgLib = LoadLibrary(L"CoreMessaging.dll"); | |
typedef HRESULT(WINAPI* CreateDispatcherQueueForCurrentThread)( | |
_Deref_out_ ABI::Windows::System::IDispatcherQueue** dispatcherQueueController); | |
auto pCreateDispatcherQueueForCurrentThread = | |
(CreateDispatcherQueueForCurrentThread)GetProcAddress(coreMsgLib, "CreateDispatcherQueueForCurrentThread"); | |
// if it's NULL means we are on 14393 or older (DispatcherQueue doesn't exists in these versions.) | |
if (!pCreateDispatcherQueueForCurrentThread) | |
return nullptr; | |
winrt::Windows::System::DispatcherQueue controller{ nullptr }; | |
winrt::check_hresult(pCreateDispatcherQueueForCurrentThread(reinterpret_cast<ABI::Windows::System::IDispatcherQueue**>(winrt::put_abi(controller)))); | |
return controller; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment