Skip to content

Commit

Permalink
Simplify dwrite.dll loading process (#6538)
Browse files Browse the repository at this point in the history
* Simplify dwrite loading process

All supported OS always has `dwrite.dll`.

* Remove noop
  • Loading branch information
kant2002 authored Apr 27, 2023
1 parent e80b23b commit 9b6baa0
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions src/Microsoft.DotNet.Wpf/src/Shared/cpp/dwriteloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,9 @@
namespace WPFUtils
{

#if defined(__cplusplus_cli)
#endif
HMODULE LoadDWriteLibraryAndGetProcAddress(void **pfncptrDWriteCreateFactory)
{
HMODULE hDWriteLibrary = nullptr;

// KB2533623 introduced the LOAD_LIBRARY_SEARCH_SYSTEM32 flag. It also introduced
// the AddDllDirectory function. We test for presence of AddDllDirectory as an
// indirect evidence for the support of LOAD_LIBRARY_SEARCH_SYSTEM32 flag.
HMODULE hKernel32 = GetModuleHandle(L"kernel32.dll");
if (hKernel32 != nullptr)
{
if (GetProcAddress(hKernel32, "AddDllDirectory") != nullptr)
{
// All supported platforms newer than Vista SP2 shipped with dwrite.dll.
// On Vista SP2, the .NET servicing process will ensure that a MSU containing
// dwrite.dll will be delivered as a prerequisite - effectively guaranteeing that
// this following call to LoadLibraryEx(dwrite.dll) will succeed, and that it will
// not be susceptible to typical DLL planting vulnerability vectors.
hDWriteLibrary = LoadLibraryEx(L"dwrite.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
}
else
{
// LOAD_LIBRARY_SEARCH_SYSTEM32 is not supported on this OS.
// Fall back to using plain ol' LoadLibrary
// There is risk that this call might fail, or that it might be
// susceptible to DLL hijacking.
hDWriteLibrary = LoadLibrary(L"dwrite.dll");
}
}

HMODULE hDWriteLibrary = LoadLibraryEx(L"dwrite.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (hDWriteLibrary)
{
*pfncptrDWriteCreateFactory = GetProcAddress(hDWriteLibrary, "DWriteCreateFactory");
Expand Down

0 comments on commit 9b6baa0

Please sign in to comment.