Calling winrt::Windows::System::UserProfile::GlobalizationPreferences::Languages(); crashes after re-initializing Ole by calling OleUninitialize(); and then OleInitialize(NULL);.
We found that during debugging of https://bugreports.qt.io/browse/QTBUG-103611.
#include <Ole2.h>
#include <iostream>
# include <winrt/base.h>
// Workaround for Windows SDK bug.
// See https://github.com/microsoft/Windows.UI.Composition-Win32-Samples/issues/47
namespace winrt::impl
{
template <typename Async>
auto wait_for(Async const& async, Windows::Foundation::TimeSpan const& timeout);
}
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.System.UserProfile.h>
int main()
{
OleInitialize(NULL);
{
auto lang = winrt::Windows::System::UserProfile::GlobalizationPreferences::Languages();
std::cout << "First call succeeded!\n";
}
OleUninitialize();
OleInitialize(NULL);
{
// the next line crashes
auto lang = winrt::Windows::System::UserProfile::GlobalizationPreferences::Languages();
std::cout << "Second call succeeded!\n";
}
OleUninitialize();
}
callstack of crash:
OleInitializeCrashReproducer.exe!winrt::impl::consume_Windows_System_UserProfile_IGlobalizationPreferencesStatics<winrt::Windows::System::UserProfile::IGlobalizationPreferencesStatics>::Languages() Line 167 C++
OleInitializeCrashReproducer.exe!winrt::Windows::System::UserProfile::GlobalizationPreferences::Languages'::
2'::<lambda_1>::operator() < winrt::Windows::System::UserProfile::IGlobalizationPreferencesStatics const& > (const winrt::Windows::System::UserProfile::IGlobalizationPreferencesStatics & f) Line 896 C++
OleInitializeCrashReproducer.exe!winrt::impl::factory_cache_entry<winrt::Windows::System::UserProfile::GlobalizationPreferences, winrt::Windows::System::UserProfile::IGlobalizationPreferencesStatics>::call<winrt: : Windows::System::UserProfile::GlobalizationPreferences::Languages'::
2'::<lambda_1> &>(winrt::Windows::System::UserProfile::GlobalizationPreferences::Languages::__l2::<lambda_1> &callback) Line 5372 C++
OleInitializeCrashReproducer.exe!winrt::impl::call_factory<winrt::Windows::System::UserProfile::GlobalizationPreferences, winrt::Windows::System::UserProfile::IGlobalizationPreferencesStatics, winrt: : Windows::System::UserProfile::GlobalizationPreferences::Languages'::
2'::<lambda_1>>(winrt::Windows::System::UserProfile::GlobalizationPreferences::Languages::__l2::<lambda_1> && callback) Line 5450 C++
OleInitializeCrashReproducer.exe!winrt::Windows::System::UserProfile::GlobalizationPreferences::Languages() Line 896 C++
OleInitializeCrashReproducer.exe!main() Line 31 C++
[External Code]