hstring_compare.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/win/hstring_compare.h"
  5. #include <winstring.h>
  6. #include "base/native_library.h"
  7. #include "base/win/windows_version.h"
  8. namespace base {
  9. namespace win {
  10. HRESULT HStringCompare(HSTRING string1, HSTRING string2, INT32* result) {
  11. using CompareStringFunc = decltype(&::WindowsCompareStringOrdinal);
  12. static const auto compare_string_func = []() -> CompareStringFunc {
  13. if (GetVersion() < Version::WIN8)
  14. return nullptr;
  15. NativeLibraryLoadError load_error;
  16. NativeLibrary combase_module =
  17. PinSystemLibrary(FILE_PATH_LITERAL("combase.dll"), &load_error);
  18. if (load_error.code)
  19. return nullptr;
  20. return reinterpret_cast<CompareStringFunc>(
  21. GetFunctionPointerFromNativeLibrary(combase_module,
  22. "WindowsCompareStringOrdinal"));
  23. }();
  24. if (!compare_string_func)
  25. return E_FAIL;
  26. return compare_string_func(string1, string2, result);
  27. }
  28. } // namespace win
  29. } // namespace base