3939#include < strsafe.h>
4040#include < wrl\client.h>
4141#include < wrl\implements.h>
42- #pragma comment(lib, "runtimeobject.lib")
4342
4443using namespace Microsoft ::WRL;
4544using namespace Windows ::Foundation;
@@ -55,6 +54,14 @@ class StringReferenceWrapper
5554 // Warning: The caller must ensure the lifetime of the buffer outlives this
5655 // object as it does not make a copy of the wide string memory.
5756
57+ static bool isSupported ()
58+ {
59+ static char cachedRes = -1 ;
60+ if (cachedRes > -1 ) return cachedRes;
61+ cachedRes = ::LoadLibrary (L" API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL" ) != 0 ;
62+ return cachedRes;
63+ }
64+
5865 StringReferenceWrapper (_In_reads_(length) PCWSTR stringRef, _In_ UINT32 length) throw ()
5966 {
6067 HRESULT hr = WindowsCreateStringReference (stringRef, length, &_header, &_hstring);
@@ -359,9 +366,18 @@ HRESULT NotificationManagerToastWin::CreateToast(_In_ IToastNotificationManagerS
359366}
360367
361368bool NotificationManagerToastWin::IsSupported () {
362- ComPtr<IToastNotificationManagerStatics> toastStatics;
363- HRESULT hr = GetActivationFactory (StringReferenceWrapper (RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get (), &toastStatics);
364- return SUCCEEDED (hr);
369+ static char cachedRes = -1 ;
370+
371+ if (cachedRes > -1 ) return cachedRes;
372+ cachedRes = 0 ;
373+
374+ if (StringReferenceWrapper::isSupported ()) {
375+ ComPtr<IToastNotificationManagerStatics> toastStatics;
376+ HRESULT hr = GetActivationFactory (StringReferenceWrapper (RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get (), &toastStatics);
377+ cachedRes = SUCCEEDED (hr);
378+ }
379+
380+ return cachedRes;
365381}
366382
367383NotificationManagerToastWin::NotificationManagerToastWin () {
0 commit comments