title: Sending "AutomationElement" from C++ (IUIAutomationElement) to C# (AutomationElement)
body: <p>I've a listener in C++ which monitors for window messages and gets the <code>HWND</code> of the newly created windows. Using UIAutomation SDK for C++, I am able to get the AutomationElement and associated information from it</p>
  
  <pre><code>    if (pUIAutomation) {
          IUIAutomationElement *e = nullptr;
          auto hr = pUIAutomation-&gt;ElementFromHandle(hwnd, &amp;e);
      }
  </code></pre>
  
  <p><code>pUIAutomation</code> is pointer of type <code>IUIAutomation</code> obtained by calling <code>CoCreateInstance</code>.</p>
  
  <p>Is there a way to pass this <code>IUIAutomationElement *</code> to C# <code>AutomationElement</code>? There is a c# module where further processing needs to be done.</p>
  
  <p>I am aware that C# itself can directly listen to events and get the <code>AutomationElement</code> of new windows, but I can't use it. Also, <code>hwnd</code> can be passed to C# module and <code>AutomationElement.FromHandle(hwnd)</code> can be used to get it.</p>
  
  <p>I am looking if I can directly pass the automation element itself. </p>
  
  <p>Thanks in advance</p>