DelayLoadLibrary.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. //#include <roapi.h>
  7. #include "activation.h"
  8. #include <winstring.h>
  9. #include "RoParameterizedIID.h"
  10. namespace Js
  11. {
  12. class DelayLoadWinRtString : public DelayLoadLibrary
  13. {
  14. private:
  15. // WinRTString specific functions
  16. typedef HRESULT FNCWindowsCreateString(const WCHAR *, UINT32, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING *);
  17. typedef FNCWindowsCreateString* PFNCWindowsCreateString;
  18. PFNCWindowsCreateString m_pfnWindowsCreateString;
  19. typedef HRESULT FNCWindowsCreateStringReference(const WCHAR *, UINT32, HSTRING_HEADER *, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING *);
  20. typedef FNCWindowsCreateStringReference* PFNCWindowsCreateStringReference;
  21. PFNCWindowsCreateStringReference m_pfnWindowsCreateStringReference;
  22. typedef PCWSTR FNCWindowsGetStringRawBuffer(HSTRING, UINT32*);
  23. typedef FNCWindowsGetStringRawBuffer* PFNCWindowsGetStringRawBuffer;
  24. PFNCWindowsGetStringRawBuffer m_pfWindowsGetStringRawBuffer;
  25. typedef HRESULT FNCWindowsDeleteString(HSTRING);
  26. typedef FNCWindowsDeleteString* PFNCWindowsDeleteString;
  27. PFNCWindowsDeleteString m_pfnWindowsDeleteString;
  28. typedef HRESULT FNCWindowsCompareStringOrdinal(HSTRING,HSTRING,INT32*);
  29. typedef FNCWindowsCompareStringOrdinal* PFNCWindowsCompareStringOrdinal;
  30. PFNCWindowsCompareStringOrdinal m_pfnWindowsCompareStringOrdinal;
  31. typedef HRESULT FNCWindowsDuplicateString(HSTRING, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING*);
  32. typedef FNCWindowsDuplicateString* PFNCWindowsDuplicateString;
  33. PFNCWindowsDuplicateString m_pfnWindowsDuplicateString;
  34. public:
  35. DelayLoadWinRtString() : DelayLoadLibrary(),
  36. m_pfnWindowsCreateString(NULL),
  37. m_pfWindowsGetStringRawBuffer(NULL),
  38. m_pfnWindowsDeleteString(NULL),
  39. m_pfnWindowsCreateStringReference(NULL),
  40. m_pfnWindowsDuplicateString(NULL),
  41. m_pfnWindowsCompareStringOrdinal(NULL) { }
  42. virtual ~DelayLoadWinRtString() { }
  43. LPCTSTR GetLibraryName() const { return _u("api-ms-win-core-winrt-string-l1-1-0.dll"); }
  44. virtual HRESULT WindowsCreateString(_In_reads_opt_(length) const WCHAR * sourceString, UINT32 length, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING * string);
  45. virtual HRESULT WindowsCreateStringReference(_In_reads_opt_(length + 1) const WCHAR * sourceString, UINT32 length, _Out_ HSTRING_HEADER * header, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING * string);
  46. virtual HRESULT WindowsDeleteString(_In_opt_ HSTRING string);
  47. virtual PCWSTR WindowsGetStringRawBuffer(_In_opt_ HSTRING string, _Out_opt_ UINT32 * length);
  48. virtual HRESULT WindowsCompareStringOrdinal(_In_opt_ HSTRING string1, _In_opt_ HSTRING string2, _Out_ INT32 * result);
  49. virtual HRESULT WindowsDuplicateString(_In_opt_ HSTRING original, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING * newString);
  50. };
  51. #ifdef INTL_WINGLOB
  52. class DelayLoadWindowsGlobalization sealed : public DelayLoadWinRtString
  53. {
  54. private:
  55. // DelayLoadWindowsGlobalization specific functions
  56. typedef HRESULT FNCWDllGetActivationFactory(HSTRING clsid, IActivationFactory** factory);
  57. typedef FNCWDllGetActivationFactory* PFNCWDllGetActivationFactory;
  58. PFNCWDllGetActivationFactory m_pfnFNCWDllGetActivationFactory;
  59. Js::DelayLoadWinRtString *winRTStringLibrary;
  60. bool winRTStringsPresent;
  61. bool hasGlobalizationDllLoaded;
  62. public:
  63. DelayLoadWindowsGlobalization() : DelayLoadWinRtString(),
  64. m_pfnFNCWDllGetActivationFactory(nullptr),
  65. winRTStringLibrary(nullptr),
  66. winRTStringsPresent(false),
  67. hasGlobalizationDllLoaded(false) { }
  68. virtual ~DelayLoadWindowsGlobalization() { }
  69. LPCTSTR GetLibraryName() const
  70. {
  71. return _u("windows.globalization.dll");
  72. }
  73. LPCTSTR GetWin7LibraryName() const
  74. {
  75. return _u("jsIntl.dll");
  76. }
  77. void Ensure(Js::DelayLoadWinRtString *winRTStringLibrary);
  78. HRESULT DllGetActivationFactory(__in HSTRING activatibleClassId, __out IActivationFactory** factory);
  79. bool HasGlobalizationDllLoaded();
  80. HRESULT WindowsCreateString(_In_reads_opt_(length) const WCHAR * sourceString, UINT32 length, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING * string) override;
  81. HRESULT WindowsCreateStringReference(_In_reads_opt_(length+1) const WCHAR * sourceString, UINT32 length, _Out_ HSTRING_HEADER * header, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING * string) override;
  82. HRESULT WindowsDeleteString(_In_opt_ HSTRING string) override;
  83. PCWSTR WindowsGetStringRawBuffer(_In_opt_ HSTRING string, _Out_opt_ UINT32 * length) override;
  84. HRESULT WindowsCompareStringOrdinal(_In_opt_ HSTRING string1, _In_opt_ HSTRING string2, _Out_ INT32 * result) override;
  85. HRESULT WindowsDuplicateString(_In_opt_ HSTRING original, _Outptr_result_maybenull_ _Result_nullonfailure_ HSTRING *newString) override;
  86. };
  87. #endif
  88. class DelayLoadWinRtFoundation sealed : public DelayLoadLibrary
  89. {
  90. private:
  91. // DelayLoadWindowsFoundation specific functions
  92. typedef HRESULT FNCWRoGetActivationFactory(HSTRING clsid, REFIID iid, IActivationFactory** factory);
  93. typedef FNCWRoGetActivationFactory* PFNCWRoGetActivationFactory;
  94. PFNCWRoGetActivationFactory m_pfnFNCWRoGetActivationFactory;
  95. public:
  96. DelayLoadWinRtFoundation() : DelayLoadLibrary(),
  97. m_pfnFNCWRoGetActivationFactory(nullptr) { }
  98. virtual ~DelayLoadWinRtFoundation() { }
  99. LPCTSTR GetLibraryName() const { return _u("api-ms-win-core-winrt-l1-1-0.dll"); }
  100. HRESULT RoGetActivationFactory(
  101. __in HSTRING activatibleClassId,
  102. __in REFIID iid,
  103. __out IActivationFactory** factory);
  104. };
  105. class DelayLoadWinCoreProcessThreads sealed : public DelayLoadLibrary
  106. {
  107. private:
  108. // LoadWinCoreMemory specific functions
  109. typedef BOOL FNCGetProcessInformation(HANDLE, PROCESS_INFORMATION_CLASS, PVOID, SIZE_T);
  110. typedef FNCGetProcessInformation* PFNCGetProcessInformation;
  111. PFNCGetProcessInformation m_pfnGetProcessInformation;
  112. public:
  113. DelayLoadWinCoreProcessThreads() :
  114. DelayLoadLibrary(),
  115. m_pfnGetProcessInformation(nullptr)
  116. {
  117. }
  118. LPCTSTR GetLibraryName() const { return _u("api-ms-win-core-processthreads-l1-1-3.dll"); }
  119. BOOL GetProcessInformation(
  120. __in HANDLE hProcess,
  121. __in PROCESS_INFORMATION_CLASS ProcessInformationClass,
  122. __out_bcount(nLength) PVOID lpBuffer,
  123. __in SIZE_T nLength
  124. );
  125. };
  126. }