Skip to content

Commit 5ebe532

Browse files
jefry-vcuberogerwang
authored andcommitted
fix dll dependency problem for non win8
Fix nwjs#2568 Fix nwjs#2574
1 parent ef6af9b commit 5ebe532

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/nw_notification_manager_toast_win.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include <strsafe.h>
4040
#include <wrl\client.h>
4141
#include <wrl\implements.h>
42-
#pragma comment(lib, "runtimeobject.lib")
4342

4443
using namespace Microsoft::WRL;
4544
using 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

361368
bool 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

367383
NotificationManagerToastWin::NotificationManagerToastWin() {

0 commit comments

Comments
 (0)