I'm new to the Speech API, but I can at least answer this question:
How the hell is the script triggered to cause the OnRecognition function to kick off?
COM_ConnectObject connects events exposed by an object to the corresponding functions in script.
If I understand COM_ConnectObject correctly, it works as follows:
Retrieve an IConnectionPoint interface (pconn) representing the events exposed by the object.
Construct an object and an IDispatch interface. This object is referred to as an "event sink" (pevent or psink.) RegisterCallback and NumPut are used to construct the interface, with the actual code contained in COM_DispInterface.
Call pconn->Advise(psink) to create a connection between the connection point and the event sink.
When the source object raises an event, it calls the Invoke method of our event sink. On the AutoHotkey side, COM_DispInterface is executed with A_EventInfo == 6. RegisterCallback and DllCall are used to dynamically call the appropriate function, based on a script-defined prefix and the name of the event being raised.
i.e. what faculties of AHK are you employing to cause this functionality to exist.
In summary:
[*:ikdwiyae]NumGet and DllCall to call methods of COM interfaces.
[*:ikdwiyae]VarSetCapacity, RegisterCallback and NumPut to construct a COM interface.
[*:ikdwiyae]RegisterCallback and DllCall to call a function dynamically.
Edit:Okay, now I can answer another one.
Is there a way to tell it to receive All words SDK recognizes?
Replace everything from COM_Init() to ExitApp with:
COM_Init()
plistener:= COM_CreateObject("SAPI.SpSharedRecognizer")
pcontext := COM_Invoke(plistener, "CreateRecoContext")
pgrammar := COM_Invoke(pcontext , "CreateGrammar")
COM_Invoke(pgrammar, "DictationSetState", [color=red]1[/color])
; No rules to set up!
pevent := COM_ConnectObject(pcontext, "On")
Return
CleanUp:
COM_Release(pevent)
; No rules to clean up!
COM_Release(pgrammar)
COM_Release(pcontext)
COM_Release(plistener)
COM_Term()
ExitApp