Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "Std.h"
#include "fileHelpers.h"
#include <winstring.h>
#include "dllload.h"
 
extern "C" {
HRESULT __stdcall OS_RoGetActivationFactory(HSTRING classId, GUID const& iid, void** factory) noexcept;
}
 
#ifdef _M_IX86
#pragma comment(linker, "/alternatename:_OS_RoGetActivationFactory@12=_RoGetActivationFactory@12")
#else
#pragma comment(linker, "/alternatename:OS_RoGetActivationFactory=RoGetActivationFactory")
#endif
 
bool starts_with(std::wstring_view value, std::wstring_view match) noexcept {
  return 0 == value.compare(0, match.size(), match);
}
 
HRESULT __stdcall WINRT_RoGetActivationFactory(HSTRING classId_hstring, GUID const& iid, void** factory) noexcept {
  *factory = nullptr;
  std::wstring_view name{WindowsGetStringRawBuffer(classId_hstring, nullptr), WindowsGetStringLen(classId_hstring)};
  HMODULE library{nullptr};
 
  std::wostringstream dll;
  dll << BINARY_NAME;
 
  std::wstring winml_dll_name = dll.str();
  std::wstring winml_dll_path = FileHelpers::GetWinMLPath() + winml_dll_name;
  std::wstring winml_dll_prefix = winml_dll_name.substr(0, winml_dll_name.size() - 3);
  if (starts_with(name, winml_dll_prefix)) {
    const wchar_t* lib_path = winml_dll_path.c_str();
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
    library = LoadLibraryExW(lib_path, nullptr, 0);
#else
    library = LoadPackagedLibrary(lib_path, 0);
#endif
  } else {
    return OS_RoGetActivationFactory(classId_hstring, iid, factory);
  }
 
  if (!library) {
    return HRESULT_FROM_WIN32(GetLastError());
  }
 
  using DllGetActivationFactory = HRESULT __stdcall(HSTRING classId, void** factory);
  auto call = reinterpret_cast<DllGetActivationFactory*>(GetProcAddress(library, "DllGetActivationFactory"));
 
  if (!call) {
    HRESULT const hr = HRESULT_FROM_WIN32(GetLastError());
    WINRT_VERIFY(FreeLibrary(library));
    return hr;
  }
 
  winrt::com_ptr<wf::IActivationFactory> activation_factory;
  HRESULT const hr = call(classId_hstring, activation_factory.put_void());
 
  if (FAILED(hr)) {
    WINRT_VERIFY(FreeLibrary(library));
    return hr;
  }
 
  if (winrt::guid(iid) != winrt::guid_of<wf::IActivationFactory>()) {
    return activation_factory->QueryInterface(iid, factory);
  }
 
  *factory = activation_factory.detach();
  return S_OK;
}
 
int32_t __stdcall WINRT_RoGetActivationFactory(void* classId, winrt::guid const& iid, void** factory) noexcept {
  return WINRT_RoGetActivationFactory((HSTRING)classId, (GUID)iid, factory);
}