================
@@ -302,3 +304,64 @@ Environment Host::GetEnvironment() {
   }
   return env;
 }
+
+/// Manages the lifecycle of a Windows Event's Source.
+/// The destructor will call DeregisterEventSource.
+/// This class is meant to be used with \ref llvm::ManagedStatic.
+class WindowsEventLog {
+public:
+  WindowsEventLog() : handle(RegisterEventSource(nullptr, L"lldb")) {}
+
+  ~WindowsEventLog() {
+    if (handle)
+      DeregisterEventSource(handle);
+  }
+
+  HANDLE GetHandle() const { return handle; }
+
+private:
+  HANDLE handle;
+};
+
+static llvm::ManagedStatic<WindowsEventLog> event_log;
+
+static LPCWSTR AnsiToUtf16(const std::string &ansi) {
+  if (ansi.empty())
+    return nullptr;
+  const int unicode_length =
+      MultiByteToWideChar(CP_ACP, 0, ansi.c_str(), -1, nullptr, 0);
+  WCHAR *unicode = new WCHAR[unicode_length];
----------------
Michael137 wrote:

Not sure about idiomatic Windows code but could we make this a 
`std::unique_ptr<WCHAR[]>`?

https://github.com/llvm/llvm-project/pull/150213
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to