Preview:
[color=red]UIAutomation := ImportTypeLib(A_WinDir "\System32\UIAutomationCore.dll")[/color] automation := new UIAutomation.IUIAutomation(new UIAutomation.CUIAutomation()) MsgBox % "Retrieved condition: " automation.ControlViewCondition automation.RemoveAllEventHandlers() desktop := new UIAutomation.IUIAutomationElement(automation.GetRootElement()) MsgBox % "Desktop process PID: " desktop.CurrentProcessId desktop.SetFocus() MsgBox % "The desktop has " . (desktop.CurrentOrientation == UIAutomation.OrientationType.Horizontal ? "horizontal" : "vertical") . " orientation."_____________________________________________________________________________________________________________________________________________________
Basics:
Since the support of memory addresses in DllCall, COM can be called from within AutoHotkey. This way is a little inconvenient, and so the COM stdlib was created. With AHK_L, builtin support for calling dispatch interfaces was added.
However, there is still a lot of COM that can't be called like that. This still needed to be invoked using DllCall - until now.
_____________________________________________________________________________________________________________________________________________________
Usage:
This library allows you to call COM methods the same way as you do for dispatch interfaces (such as Office, InternetExplorer and more). It also adds more convenience: you can also use enumerations and structures.
To use it, however, you need a COM type library. There are a lot of them registered with your system. You can view them using this script (included in the download). If you have the Windows SDK, there are even more libs which can be compiled from *.idl files. However, the end-user also requires this lib (ensure you are allowed to redistribute a lib if needed).
In your script, call ImportTypeLib() with either the file path, or, if it is registered within the system, the library GUID and the library version. The return value is an object representing the type library.
You can use it as shown in the code above to retrieve enum values, create instances of included classes (Attention: this returns a pointer which must be wrapped by creating an instance of an interface.), interfaces and structures (not yet supported). From created interface instances you can call methods and retrieve or set properties just as with a dispatch object.
There are also more methods in the typelib object, and even more will be added.
Note: error handling is done with exceptions. So whenever something fails, an exception will be thrown.
_____________________________________________________________________________________________________________________________________________________
Known limitations:
[*:306pysrr]Structures are not yet supported
Edit 25/03/2012: Structures can be instantiated, members can be set. Passing structures to methods and more advanced usage is still missing.
[*:306pysrr]It is not supported to call AHK-builtin object methods on the created objects. Use the Obj*(obj, ...) form. However, avoid adding or removing fields.
Edit 13/03/2012: Enumerations now support _NewEnum() and can therefore be used with a for-Loop.
Edit 14/03/2012: The same now applies to modules.
Edit 25/03/2012: ... and for structures.
Edit 27/03/2012: Structures may also be cloned using struct._Clone() or struct.Clone(). Doing so results in an entirely new structure with new memory space, initialized with the values of the original.
Subsequent changes to either the original or the clone do not affect the other one.
[*:306pysrr]There may be some debugging messages left

Edit 13/03/2012: should be removed now.
[*:306pysrr]The entire thing will be made more stdlib-compatible.
Edit 17/03/2012: Function prefixes (ITL_) and all-in-one file should accomplish that.
[*:306pysrr]The loaded type information might refuse to do some things.
Edit 24/03/2012: For example, methods marked with the [restricted] attribute, such as IUnknown and IDispatch methods, cannot be called.
[*:306pysrr]Comments / documentation is still missing.
Edit 25/03/2012: documentation has been started, first stuff is available under maul-esel.github.com/ImportTypeLib_____________________________________________________________________________________________________________________________________________________
Feedback required
This is still in early alpha stage, so please report anything you discover. Also make suggestions if you feel something could be improved. Of course anyone familiar with raw COM or OOP in AHK is welcome to fork and contribute on github or to submit fixes here.
_____________________________________________________________________________________________________________________________________________________
Download (for regular users)
Download Project (for developers)
As stated in the post title, this requires (latest) AHK_L. It will later be ported to AHK v2.
Regards
maul.esel