I am trying to use Microsoft UI Automation Project.
What I understand so far after reading through the Functional Tests, that are part of Project, that IUIAutomationElement needs to be converted to AutomationElement, that is exposed as a WinRT interface.
I am trying it via C# where I am using IUIAutomationElement from Interop.UIAutomatonClient library and trying it to cast to WinRT AutomationElement.
The theory is based on the code from functional tests itself that casts IUIAutomationElement COM Pointer to winrt::AutomationElement
If my understanding is correct, then how could I achieve this? A sample where I just try to get the GUI handle and get its IUIAutomationElement. Evidently, I cannot just use ImportElement function that expects AutomationElement as there is no explicit or implicit cast that exists.
'''
var processes = Process.GetProcessesByName("myprocess");
var process = processes.FirstOrDefault(p => p.MainWindowHandle != IntPtr.Zero);
IUIAutomation automation = new CUIAutomation();
IUIAutomationElement automationElement = automation.ElementFromHandle(process.Handle);
AutomationRemoteOperation op = new AutomationRemoteOperation();
op.ImportElement(automationElement);// error
'''