Skip to content

Commit 37f0c4e

Browse files
authored
Restore Win7 functionality (more correctly this time) (#898)
1 parent ede68ed commit 37f0c4e

File tree

6 files changed

+26
-11
lines changed

6 files changed

+26
-11
lines changed

strings/base_activation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace winrt::impl
3434
}
3535

3636
static int32_t(__stdcall * handler)(void* classId, winrt::guid const& iid, void** factory) noexcept;
37-
impl::load_runtime_function("RoGetActivationFactory", handler, fallback_RoGetActivationFactory);
37+
impl::load_runtime_function(L"combase.dll", "RoGetActivationFactory", handler, fallback_RoGetActivationFactory);
3838
hresult hr = handler(*(void**)(&name), guid, result);
3939

4040
if (hr == impl::error_not_initialized)

strings/base_agile_ref.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ namespace winrt::impl
122122
};
123123

124124
template <typename F, typename L>
125-
void load_runtime_function(char const* name, F& result, L fallback) noexcept
125+
void load_runtime_function(wchar_t const* library, char const* name, F& result, L fallback) noexcept
126126
{
127127
if (result)
128128
{
129129
return;
130130
}
131131

132-
result = reinterpret_cast<F>(WINRT_IMPL_GetProcAddress(WINRT_IMPL_LoadLibraryW(L"combase.dll"), name));
132+
result = reinterpret_cast<F>(WINRT_IMPL_GetProcAddress(WINRT_IMPL_LoadLibraryW(library), name));
133133

134134
if (result)
135135
{
@@ -167,7 +167,7 @@ namespace winrt::impl
167167
inline hresult get_agile_reference(winrt::guid const& iid, void* object, void** reference) noexcept
168168
{
169169
static int32_t(__stdcall * handler)(uint32_t options, winrt::guid const& iid, void* object, void** reference) noexcept;
170-
load_runtime_function("RoGetAgileReference", handler, fallback_RoGetAgileReference);
170+
load_runtime_function(L"combase.dll", "RoGetAgileReference", handler, fallback_RoGetAgileReference);
171171
return handler(0, iid, object, reference);
172172
}
173173
}

strings/base_coroutine_threadpool.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,17 @@ WINRT_EXPORT namespace winrt
433433

434434
private:
435435

436+
static int32_t __stdcall fallback_SetThreadpoolTimerEx(winrt::impl::ptp_timer, void*, uint32_t, uint32_t) noexcept
437+
{
438+
return 0; // pretend timer has already triggered and a callback is on its way
439+
}
440+
436441
void fire_immediately() noexcept
437442
{
438-
if (WINRT_IMPL_SetThreadpoolTimer(m_timer.get(), nullptr, 0, 0))
443+
static int32_t(__stdcall* handler)(winrt::impl::ptp_timer, void*, uint32_t, uint32_t) noexcept;
444+
impl::load_runtime_function(L"kernel32.dll", "SetThreadpoolTimerEx", handler, fallback_SetThreadpoolTimerEx);
445+
446+
if (handler(m_timer.get(), nullptr, 0, 0))
439447
{
440448
int64_t now = 0;
441449
WINRT_IMPL_SetThreadpoolTimer(m_timer.get(), &now, 0, 0);
@@ -532,10 +540,17 @@ WINRT_EXPORT namespace winrt
532540
}
533541

534542
private:
543+
static int32_t __stdcall fallback_SetThreadpoolWaitEx(winrt::impl::ptp_wait, void*, void*, void*) noexcept
544+
{
545+
return 0; // pretend wait has already triggered and a callback is on its way
546+
}
535547

536548
void fire_immediately() noexcept
537549
{
538-
if (WINRT_IMPL_SetThreadpoolWait(m_wait.get(), nullptr, nullptr))
550+
static int32_t(__stdcall* handler)(winrt::impl::ptp_wait, void*, void*, void*) noexcept;
551+
impl::load_runtime_function(L"kernel32.dll", "SetThreadpoolWaitEx", handler, fallback_SetThreadpoolWaitEx);
552+
553+
if (handler(m_wait.get(), nullptr, nullptr, nullptr))
539554
{
540555
int64_t now = 0;
541556
WINRT_IMPL_SetThreadpoolWait(m_wait.get(), WINRT_IMPL_GetCurrentProcess(), &now);

strings/base_error.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ WINRT_EXPORT namespace winrt
312312
void originate(hresult const code, void* message) noexcept
313313
{
314314
static int32_t(__stdcall* handler)(int32_t error, void* message, void* exception) noexcept;
315-
impl::load_runtime_function("RoOriginateLanguageException", handler, fallback_RoOriginateLanguageException);
315+
impl::load_runtime_function(L"combase.dll", "RoOriginateLanguageException", handler, fallback_RoOriginateLanguageException);
316316
WINRT_VERIFY(handler(code, message, nullptr));
317317

318318
com_ptr<impl::IErrorInfo> info;
@@ -625,7 +625,7 @@ WINRT_EXPORT namespace winrt
625625
[[noreturn]] inline void terminate() noexcept
626626
{
627627
static void(__stdcall * handler)(int32_t) noexcept;
628-
impl::load_runtime_function("RoFailFastWithErrorContext", handler, impl::fallback_RoFailFastWithErrorContext);
628+
impl::load_runtime_function(L"combase.dll", "RoFailFastWithErrorContext", handler, impl::fallback_RoFailFastWithErrorContext);
629629
handler(to_hresult());
630630
abort();
631631
}

strings/base_events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ namespace winrt::impl
352352
int32_t const code = to_hresult();
353353

354354
static int32_t(__stdcall * handler)(int32_t, int32_t, void*) noexcept;
355-
impl::load_runtime_function("RoTransformError", handler, fallback_RoTransformError);
355+
impl::load_runtime_function(L"combase.dll", "RoTransformError", handler, fallback_RoTransformError);
356356
handler(code, 0, nullptr);
357357

358358
if (code == static_cast<int32_t>(0x80010108) || // RPC_E_DISCONNECTED

strings/base_extern.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ extern "C"
6565

6666
int32_t __stdcall WINRT_IMPL_TrySubmitThreadpoolCallback(void(__stdcall *callback)(void*, void* context), void* context, void*) noexcept;
6767
winrt::impl::ptp_timer __stdcall WINRT_IMPL_CreateThreadpoolTimer(void(__stdcall *callback)(void*, void* context, void*), void* context, void*) noexcept;
68-
int32_t __stdcall WINRT_IMPL_SetThreadpoolTimer(winrt::impl::ptp_timer timer, void* time, uint32_t period, uint32_t window) noexcept;
68+
void __stdcall WINRT_IMPL_SetThreadpoolTimer(winrt::impl::ptp_timer timer, void* time, uint32_t period, uint32_t window) noexcept;
6969
void __stdcall WINRT_IMPL_CloseThreadpoolTimer(winrt::impl::ptp_timer timer) noexcept;
7070
winrt::impl::ptp_wait __stdcall WINRT_IMPL_CreateThreadpoolWait(void(__stdcall *callback)(void*, void* context, void*, uint32_t result), void* context, void*) noexcept;
71-
int32_t __stdcall WINRT_IMPL_SetThreadpoolWait(winrt::impl::ptp_wait wait, void* handle, void* timeout) noexcept;
71+
void __stdcall WINRT_IMPL_SetThreadpoolWait(winrt::impl::ptp_wait wait, void* handle, void* timeout) noexcept;
7272
void __stdcall WINRT_IMPL_CloseThreadpoolWait(winrt::impl::ptp_wait wait) noexcept;
7373
winrt::impl::ptp_io __stdcall WINRT_IMPL_CreateThreadpoolIo(void* object, void(__stdcall *callback)(void*, void* context, void* overlapped, uint32_t result, std::size_t bytes, void*) noexcept, void* context, void*) noexcept;
7474
void __stdcall WINRT_IMPL_StartThreadpoolIo(winrt::impl::ptp_io io) noexcept;

0 commit comments

Comments
 (0)