I am trying to play around with uiautomation, using your importtypelib scripts.
in your misc\test.ahk example, the following lines fail:
pt := new UIAutomation.tagPOINT(), pt.x := 400, pt.y := 400 elem2 := automation.ElementFromPoint(pt)
pt := new UIAutomation.tagPOINT(), pt.x := 400, pt.y := 400 elem2 := automation.ElementFromPoint(pt)
AcReport.AcRptEngine mac; //AcReport is the namespace mac = new AcReport.AcRptEngine(); mac.ShowDesigner();C++ Code
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. CoInitialize(NULL); IAcRptEnginePtr ac; ac.CreateInstance(__uuidof(AcRptEngine)); ac->ShowDesigner(); ac.Release(); CoUninitialize(); return 0; }I port it to ahk and my code is:
AcRptEng := ImportTypeLib(dll) rpt := New AcRptEng.IAcRptEngine(new AcRptEng.AcRptEngine()) rpt2 := new AcRptEng.AcRptEngine() MsgBox % IsObject(rpt) MsgBox % IsObject(rpt2) rpt.ShowDesigner()Neither rpt nor rpt2 is not an object.
rpt2
is a pointer, not an object) - but there's no wrapper for the interface. This is intentional.IAcRptEngine
interface inherits IDispatch
- therefore you don't need this lib. Regular and tested AHK code:CLSID_AcRptEngine := "{C84DF69C-0227-4846-919B-6B31168FE68A}", IID_IAcRptEngine := "{78DD38D7-B85E-4075-893E-6639C23EA85E}" ; variables for readability engine := ComObjCreate(CLSID_AcRptEngine, IID_IAcRptEngine) ; create object pointer - need CLSID and IID because no human-friendly name (ProgID) provided engine := ComObjEnwrap(engine) ; make an AHK object for the pointer engine.Preview() ; call a method
since I am new to C# I get errors with this script:
#include <ImportTypeLib> UIAutomation := ImportTypeLib(A_WinDir "\System32\UIAutomationCore.dll") automation := new UIAutomation.IUIAutomation(new UIAutomation.CUIAutomation()) automation.RemoveAllEventHandlers() desktop := new UIAutomation.IUIAutomationElement(automation.GetRootElement()) menu := desktop.FindFirst(UIAutomation.TreeScope.Children, new UIAutomation.PropertyCondition(UIAutomation.AutomationElement.ProcessIdProperty, winexist("Menu.exe"))) datagrid := Menu.FindFirst(UIAutomation.TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "dgHisReport"))
The error says:
Failed to call method "IUIAutomationElement::FindFirst()"
ITypeInfo::Invoke() failed
HRESULT: -2147352571
Invalid argument: #1
Can anyonehelp me to make it work ? Thx