Skip to content

Commit acbcd27

Browse files
committed
Use bcp47mrm header
1 parent 544211d commit acbcd27

File tree

4 files changed

+4
-70
lines changed

4 files changed

+4
-70
lines changed

dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/ApplicationLanguages.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
#include "ApplicationLanguages.h"
66
#include "Microsoft.Windows.Globalization.ApplicationLanguages.g.cpp"
77

8+
#include <bcp47mrm.h>
89
#include <winrt/Windows.Globalization.h>
910

1011
#include <AppModel.Identity.h>
1112

12-
#include "Helper.h"
13-
1413
namespace winrt::Microsoft::Windows::Globalization::implementation
1514
{
1615
hstring ApplicationLanguages::m_language;
@@ -42,7 +41,7 @@ namespace winrt::Microsoft::Windows::Globalization::implementation
4241

4342
void ApplicationLanguages::PrimaryLanguageOverride(hstring const& language)
4443
{
45-
bool isValidLanguageTag = _DefIsWellFormedTag(language.c_str());
44+
bool isValidLanguageTag = IsWellFormedTag(language.c_str());
4645

4746
THROW_HR_IF_MSG(E_INVALIDARG, !isValidLanguageTag, "The parameter is incorrect");
4847

dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/Helper.cpp

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -86,67 +86,3 @@ HRESULT GetDefaultPriFile(winrt::hstring& filePath)
8686
bool isPackaged = (hr != HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE));
8787
return GetDefaultPriFileForCurentModule(isPackaged, filePath);
8888
}
89-
90-
// Taken from Platform.h/.cpp
91-
typedef bool(WINAPI* IsWellFormedTagFunc)(PCWSTR);
92-
HMODULE g_bcp47 = (HMODULE)(-1);
93-
94-
HMODULE LoadBcp47ModuleFrom(_In_ PCWSTR moduleName)
95-
{
96-
HMODULE module = LoadLibraryExW(moduleName, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
97-
if (module != nullptr)
98-
{
99-
// All BCP47 APIs we are interested are always exported from the same dll together. So we just pick anyone for probe.
100-
IsWellFormedTagFunc func = (IsWellFormedTagFunc)(GetProcAddress(module, "IsWellFormedTag"));
101-
if (func != nullptr)
102-
{
103-
return module;
104-
}
105-
FreeLibrary(module);
106-
}
107-
108-
return nullptr;
109-
}
110-
111-
HMODULE LoadBcp47Module()
112-
{
113-
HMODULE module = LoadBcp47ModuleFrom(L"bcp47mrm.dll");
114-
if (module == nullptr)
115-
{
116-
// In downlevel OS, the API is exposed by bcp47langs.dll.
117-
module = LoadBcp47ModuleFrom(L"bcp47langs.dll");
118-
}
119-
120-
return module;
121-
}
122-
123-
void InitializeBcp47Module()
124-
{
125-
HMODULE comparand = (HMODULE)(-1);
126-
if (InterlockedCompareExchangePointer(reinterpret_cast<PVOID*>(&g_bcp47), comparand, comparand) == comparand)
127-
{
128-
HMODULE module = LoadBcp47Module();
129-
InterlockedExchangePointer(reinterpret_cast<PVOID*>(&g_bcp47), module);
130-
}
131-
}
132-
133-
BOOLEAN _DefIsWellFormedTag(_In_ PCWSTR tag)
134-
{
135-
// Before new SDK is released, we need to use LoadLibrary/GetProcAddress
136-
InitializeBcp47Module();
137-
138-
if (g_bcp47 == nullptr)
139-
{
140-
// Didn't find an implementation. Just return TRUE.
141-
return TRUE;
142-
}
143-
144-
IsWellFormedTagFunc func = (IsWellFormedTagFunc)(GetProcAddress(g_bcp47, "IsWellFormedTag"));
145-
if (func != nullptr)
146-
{
147-
return func(tag);
148-
}
149-
150-
// Should not reach here.
151-
return TRUE;
152-
}

dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/Helper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
#pragma once
55
bool IsResourceNotFound(HRESULT hr);
66
HRESULT GetDefaultPriFile(winrt::hstring& path);
7-
BOOLEAN _DefIsWellFormedTag(_In_ PCWSTR tag);

dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/Microsoft.Windows.ApplicationModel.Resources.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<DefaultLanguage>en-US</DefaultLanguage>
1818
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
1919
<Keyword>Win32Proj</Keyword>
20-
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.18362.0</WindowsTargetPlatformVersion>
20+
<WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.20348.0</WindowsTargetPlatformVersion>
2121
<WindowsTargetPlatformMinVersion>10.0.17134.0</WindowsTargetPlatformMinVersion>
2222
<!-- Need to add this otherwise the ADO build won't copy mrm.dll to output directory, and eventually the file will miss in ManagedTest.build.appxrecipe and make
2323
the tests fail to run in ADO pipeline -->
@@ -96,7 +96,7 @@
9696
<SubSystem>Console</SubSystem>
9797
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
9898
<ModuleDefinitionFile>Microsoft.Windows.ApplicationModel.Resources.def</ModuleDefinitionFile>
99-
<AdditionalDependencies>$(OutDir)..\mrm\MRM.lib;onecoreuap.lib;%(AdditionalDependencies)</AdditionalDependencies>
99+
<AdditionalDependencies>$(OutDir)..\mrm\MRM.lib;onecoreuap.lib;bcp47mrm.lib;%(AdditionalDependencies)</AdditionalDependencies>
100100
</Link>
101101
</ItemDefinitionGroup>
102102
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">

0 commit comments

Comments
 (0)