Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[AHK_L] ImportTypeLib - extended COM support!


  • Please log in to reply
22 replies to this topic
tinku99
  • Members
  • 560 posts
  • Last active: Feb 08 2015 12:54 AM
  • Joined: 03 Aug 2007
Hi maul.esel,
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)


maul.esel
  • Members
  • 790 posts
  • Last active: Jan 05 2013 09:26 PM
  • Joined: 28 Feb 2011
Sorry for the late reply, I haven't worked with ITL some time and can't access my AHK environment at the moment.

I remember that problem - I couldn't figure out how to pass structures as parameters, so this is not (yet) supported. I can't say when I have time and possibility to work on it again, so I can't help you now. :(
Join the discussion on The future of AutoHotkey
Posted Image Visit me on github Posted Image
Win7 HP SP1 64bit | AHK_L U 64bit

hughman
  • Members
  • 192 posts
  • Last active: Feb 14 2016 06:59 AM
  • Joined: 11 Feb 2007
hi, maul.esel. I want to learn this thread and apply your function to a report COM typelib named AcReport.dll.
This subject is too hard for a newbie. So I need some help to make my script woking.
the example of C# from sdk is like below:
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.
According to the sdk, the report COM typelib owns the inferface IAcRptEngine and AcRptEngine is the only object which can be created as an instance.
How should I change my script to make it running?

maul.esel
  • Members
  • 790 posts
  • Last active: Jan 05 2013 09:26 PM
  • Joined: 28 Feb 2011
Did you check it loaded the correct typelib? Because a DLL can contain several typelib resources, and IIRC by default the resource "1" is loaded - maybe your DLL uses a different name (I assume you have checked the path is correctly set).

Is it a freely available DLL so I can test it?
Join the discussion on The future of AutoHotkey
Posted Image Visit me on github Posted Image
Win7 HP SP1 64bit | AHK_L U 64bit

hughman
  • Members
  • 192 posts
  • Last active: Feb 14 2016 06:59 AM
  • Joined: 11 Feb 2007
I'm sure it has only one typelib named and version is 1.0, clsid is {6D29DD74-860E-48A1-B552-8D5A7DD855EA}.
The file is free although it's a shareware. you need regsrv it yourself.
The doc is chinese but you can browser it's methods and porperties. So I also upload it for u.
<!-- m -->https://dl.dropbox.c...62/AcReport.zip<!-- m -->
<!-- m -->https://dl.dropbox.c... ... Manual.zip<!-- m -->

maul.esel
  • Members
  • 790 posts
  • Last active: Jan 05 2013 09:26 PM
  • Joined: 28 Feb 2011
The class instance is created properly (rpt2 is a pointer, not an object) - but there's no wrapper for the interface. This is intentional.

The 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

Join the discussion on The future of AutoHotkey
Posted Image Visit me on github Posted Image
Win7 HP SP1 64bit | AHK_L U 64bit

hughman
  • Members
  • 192 posts
  • Last active: Feb 14 2016 06:59 AM
  • Joined: 11 Feb 2007
thanks very much. Now I can use it more easily :)

scsnake
  • Members
  • 33 posts
  • Last active: Oct 16 2015 01:51 PM
  • Joined: 24 Mar 2009

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 ? Thxsmile.png