I know this is an old thread but I came across it and this could be a HUGE help to what I'm doing, except I can't quite get it working. I want to automate a windows application that uses wpf and winforms so I was using CUIAutomation2.au3 by junkew and that worked great. Now I have a need to integrate this into another testing tool that can use Java, Python, or C#. Our dev team uses C# so I was leaning in that direction.
Anyways, using this com server approach I was able to launch our application but when I tried to call functions like GetRootElement and FindFirst, I couldn't quite figure out the syntax. Here's a code sample:
dynamic myAu3Object = Marshal.BindToMoniker("AutoIt.Application");
// Create UI Automation object
dynamic oUIAutomation = myAu3Object.Call("ObjCreateInterface", "$sCLSID_CUIAutomation", "$sIID_IUIAutomation", "$dtagIUIAutomation");
// Get Desktop element
dynamic pDesktop = null;
myAu3Object.Call("oUIAutomation.GetRootElement", pDesktop);
var oDesktop = myAu3Object.Call("ObjCreateInterface", pDesktop, "$sIID_IUIAutomationElement", "$dtagIUIAutomationElement");
I don't believe pDesktop gets filled properly b/c if I write out oDesktop to the console it always returns '1'. I've tried a bunch of variations of the syntax but can't quite wrap my head around the proper way to do it, or if it's even possible.
I'm still learning AutoIt and have very little knowledge of C# so I'm a bit over my head but would dive right in if I knew it could work. It looks like both of those functions set the value of a variable sent to them but I'm not sure I have access to those values back in C#. Can anyone confirm that?
If more details are needed please let me know. My alternative is to create a bunch of small au3 scripts, convert them to exe files and call them externally but I was hoping to avoid that if I could. Any help would be greatly appreciated!