NETHostWindows.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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();
  53. bool CreateDelegate(const String& assemblyName, const String& qualifiedClassName, const String& methodName, void** funcOut);
  54. void WaitForDebuggerConnect();
  55. private:
  56. bool LoadCLRDLL();
  57. bool InitCLRRuntimeHost();
  58. bool TPAListContainsFile(wchar_t* fileNameWithoutExtension, wchar_t** rgTPAExtensions, int countExtensions);
  59. void RemoveExtensionAndNi(wchar_t* fileName);
  60. void AddFilesFromDirectoryToTPAList(const wchar_t* targetPath, wchar_t** rgTPAExtensions, int countExtensions);
  61. bool GenerateTPAList();
  62. bool CreateAppDomain();
  63. ICLRRuntimeHost2* clrRuntimeHost_;
  64. HMODULE clrModule_;
  65. DWORD appDomainID_;
  66. TPAStringBuffer tpaList_;
  67. };
  68. }