ComObjCreate

Creates a COM object.

ComObject := ComObjCreate(CLSID , IID)

Parameters

CLSID

Type: String

CLSID or human-readable Prog ID of the COM object to create.

IID

Type: String

The identifier of the interface to return. In most cases this is omitted; if omitted, it defaults to "{00020400-0000-0000-C000-000000000046}" (IID_IDispatch).

Return Value

Type: ComObject

This function returns a COM wrapper object.

If IID is omitted or identifies the IDispatch interface, the wrapper object has the type VT_DISPATCH (9) and the script can call properties and methods of the object using normal object syntax. Otherwise, the wrapper object has the type VT_UNKNOWN (13). In either case, ComCall can be used to call native interface methods.

Error Handling

An exception is thrown on failure, such as if a parameter is invalid or the object does not support the interface specified by IID.

Related

ComObject, ComObjGet, ComObjActive, ComObjConnect, ComObjArray, ComObjQuery, ComCall, CreateObject (MSDN)

Examples

For a constantly growing list of examples, see the following forum topic: https://www.autohotkey.com/forum/topic61509.html.

#1

ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := true  ; This is known to work incorrectly on IE7.
ie.Navigate("https://www.autohotkey.com/")

#2: Retrieve the path of the desktop's current wallpaper.

AD_GETWP_BMP := 0
AD_GETWP_LAST_APPLIED := 0x00000002
CLSID_ActiveDesktop := "{75048700-EF1F-11D0-9888-006097DEACF9}"
IID_IActiveDesktop := "{F490EB00-1240-11D1-9888-006097DEACF9}"
cchWallpaper := 260
GetWallpaper := 4

AD := ComObjCreate(CLSID_ActiveDesktop, IID_IActiveDesktop)
wszWallpaper := BufferAlloc(cchWallpaper * 2)
ComCall(GetWallpaper, AD, "ptr", wszWallpaper, "uint", cchWallpaper, "uint", AD_GETWP_LAST_APPLIED)
Wallpaper := StrGet(wszWallpaper, "UTF-16")
MsgBox "Wallpaper: " Wallpaper