comautoitearly-binding

How to early bind COM objects in AutoIt?


A colleague of mine claims that you cannot early-bind COM objects in AutoIt. Is this true?


Solution

  • AutoIt is an interpreted language even when compiled. The actual process of compiling is simply embedding the code in the interpreter (with some preprocessor elements sorted out like includes).

    As a result, binding can not be done at compile time, as there is no compile time. This means that the following will compile fine and no error will be detected.

    $oShell = ObjCreate("shell.application")
    If False Then ConsoleWrite($oShell.LolWut & @LF)
    

    Run that and nothing will happen. $oShell.LolWut will never be evaluated and so there is no error. Try it with the if test executing the statement and you get: The requested action with this object has failed.

    Edit: Also note the reply here for more details on implementation.