NETHostWindows.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #include "../../NETHost.h"
  3. #define UNICODE
  4. #include "windows.h"
  5. #include <stdio.h>
  6. #include "prebuilt/mscoree.h"
  7. #include "prebuilt/palclr.h"
  8. namespace Atomic
  9. {
  10. // Dynamically expanding string buffer to hold TPA list
  11. class TPAStringBuffer {
  12. static const int m_defaultSize = 4096;
  13. wchar_t* m_buffer;
  14. size_t m_capacity;
  15. size_t m_length;
  16. TPAStringBuffer(const TPAStringBuffer&);
  17. TPAStringBuffer& operator =(const TPAStringBuffer&);
  18. public:
  19. TPAStringBuffer() : m_capacity(0), m_buffer(nullptr), m_length(0) {
  20. }
  21. ~TPAStringBuffer() {
  22. delete[] m_buffer;
  23. }
  24. const wchar_t* CStr() const {
  25. return m_buffer;
  26. }
  27. void Append(const wchar_t* str, size_t strLen) {
  28. if (!m_buffer) {
  29. m_buffer = new wchar_t[m_defaultSize];
  30. m_capacity = m_defaultSize;
  31. }
  32. if (m_length + strLen + 1 > m_capacity) {
  33. size_t newCapacity = m_capacity * 2;
  34. wchar_t* newBuffer = new wchar_t[newCapacity];
  35. wcsncpy_s(newBuffer, newCapacity, m_buffer, m_length);
  36. delete[] m_buffer;
  37. m_buffer = newBuffer;
  38. m_capacity = newCapacity;
  39. }
  40. wcsncpy_s(m_buffer + m_length, m_capacity - m_length, str, strLen);
  41. m_length += strLen;
  42. }
  43. };
  44. class ATOMIC_API NETHostWindows : public NETHost
  45. {
  46. OBJECT(NETHostWindows);
  47. public:
  48. /// Construct.
  49. NETHostWindows(Context* context);
  50. /// Destruct.
  51. virtual ~NETHostWindows();
  52. bool Initialize(const String& coreCLRFilesAbsPath, const String& assemblyLoadPaths);
  53. bool CreateDelegate(const String& assemblyName, const String& qualifiedClassName, const String& methodName, void** funcOut);
  54. private:
  55. bool LoadCLRDLL();
  56. bool InitCLRRuntimeHost();
  57. bool TPAListContainsFile(wchar_t* fileNameWithoutExtension, wchar_t** rgTPAExtensions, int countExtensions);
  58. void RemoveExtensionAndNi(wchar_t* fileName);
  59. void AddFilesFromDirectoryToTPAList(const wchar_t* targetPath, wchar_t** rgTPAExtensions, int countExtensions);
  60. bool GenerateTPAList();
  61. bool CreateAppDomain();
  62. // this path MUST use "\" and not "/" as CoreCLR requires "\" usage in init
  63. String coreCLRFilesAbsPath_;
  64. ICLRRuntimeHost2* clrRuntimeHost_;
  65. HMODULE clrModule_;
  66. DWORD appDomainID_;
  67. TPAStringBuffer tpaList_;
  68. };
  69. }