+;------------------------------------------------------------------------------\r
+; COM.ahk Standard Library\r
+; by Sean\r
+; http://www.autohotkey.com/forum/topic22923.html\r
+;------------------------------------------------------------------------------\r
+\r
+COM_Init()\r
+{\r
+ Return DllCall("ole32\OleInitialize", "Uint", 0)\r
+}\r
+\r
+COM_Term()\r
+{\r
+ Return DllCall("ole32\OleUninitialize")\r
+}\r
+\r
+COM_VTable(ppv, idx)\r
+{\r
+ Return NumGet(NumGet(1*ppv)+4*idx)\r
+}\r
+\r
+COM_QueryInterface(ppv, IID = "")\r
+{\r
+ If DllCall(NumGet(NumGet(1*ppv)+0), "Uint", ppv, "Uint", COM_GUID4String(IID,IID ? IID : IID=0 ? "{00000000-0000-0000-C000-000000000046}" : "{00020400-0000-0000-C000-000000000046}"), "UintP", ppv)=0\r
+ Return ppv\r
+}\r
+\r
+COM_AddRef(ppv)\r
+{\r
+ Return DllCall(NumGet(NumGet(1*ppv)+4), "Uint", ppv)\r
+}\r
+\r
+COM_Release(ppv)\r
+{\r
+ Return DllCall(NumGet(NumGet(1*ppv)+8), "Uint", ppv)\r
+}\r
+\r
+COM_QueryService(ppv, SID, IID = "")\r
+{\r
+ DllCall(NumGet(NumGet(1*ppv)+4*0), "Uint", ppv, "Uint", COM_GUID4String(IID_IServiceProvider,"{6D5140C1-7436-11CE-8034-00AA006009FA}"), "UintP", psp)\r
+ DllCall(NumGet(NumGet(1*psp)+4*3), "Uint", psp, "Uint", COM_GUID4String(SID,SID), "Uint", IID ? COM_GUID4String(IID,IID) : &SID, "UintP", ppv:=0)\r
+ DllCall(NumGet(NumGet(1*psp)+4*2), "Uint", psp)\r
+ Return ppv\r
+}\r
+\r
+COM_FindConnectionPoint(pdp, DIID)\r
+{\r
+ DllCall(NumGet(NumGet(1*pdp)+ 0), "Uint", pdp, "Uint", COM_GUID4String(IID_IConnectionPointContainer, "{B196B284-BAB4-101A-B69C-00AA00341D07}"), "UintP", pcc)\r
+ DllCall(NumGet(NumGet(1*pcc)+16), "Uint", pcc, "Uint", COM_GUID4String(DIID,DIID), "UintP", pcp)\r
+ DllCall(NumGet(NumGet(1*pcc)+ 8), "Uint", pcc)\r
+ Return pcp\r
+}\r
+\r
+COM_GetConnectionInterface(pcp)\r
+{\r
+ VarSetCapacity(DIID, 16, 0)\r
+ DllCall(NumGet(NumGet(1*pcp)+12), "Uint", pcp, "Uint", &DIID)\r
+ Return COM_String4GUID(&DIID)\r
+}\r
+\r
+COM_Advise(pcp, psink)\r
+{\r
+ DllCall(NumGet(NumGet(1*pcp)+20), "Uint", pcp, "Uint", psink, "UintP", nCookie)\r
+ Return nCookie\r
+}\r
+\r
+COM_Unadvise(pcp, nCookie)\r
+{\r
+ Return DllCall(NumGet(NumGet(1*pcp)+24), "Uint", pcp, "Uint", nCookie)\r
+}\r
+\r
+COM_Enumerate(penum, ByRef Result, ByRef vt = "")\r
+{\r
+ VarSetCapacity(varResult,16,0)\r
+ If (0 = hr:=DllCall(NumGet(NumGet(1*penum)+12), "Uint", penum, "Uint", 1, "Uint", &varResult, "UintP", 0))\r
+ Result:=(vt:=NumGet(varResult,0,"Ushort"))=8||vt<0x1000&&DllCall("oleaut32\VariantChangeTypeEx","Uint",&varResult,"Uint",&varResult,"Uint",LCID,"Ushort",1,"Ushort",8)=0 ? COM_Ansi4Unicode(bstr:=NumGet(varResult,8)) . COM_SysFreeString(bstr) : NumGet(varResult,8)\r
+ Return hr\r
+}\r
+\r
+COM_Invoke(pdsp,name="",prm0="vT_NoNe",prm1="vT_NoNe",prm2="vT_NoNe",prm3="vT_NoNe",prm4="vT_NoNe",prm5="vT_NoNe",prm6="vT_NoNe",prm7="vT_NoNe",prm8="vT_NoNe",prm9="vT_NoNe")\r
+{\r
+ If name=\r
+ Return COM_Release(pdsp)\r
+ If name contains .\r
+ {\r
+ SubStr(name,1,1)!="." ? name.=".":name:=SubStr(name,2) . ".",COM_AddRef(pdsp)\r
+ Loop, Parse, name, .\r
+ {\r
+ If A_Index=1\r
+ {\r
+ name := A_LoopField\r
+ Continue\r
+ }\r
+ Else If name not contains [,(\r
+ prmn := ""\r
+ Else If InStr("])",SubStr(name,0))\r
+ Loop, Parse, name, [(,'")]\r
+ If A_Index=1\r
+ name := A_LoopField\r
+ Else prmn := A_LoopField\r
+ Else\r
+ {\r
+ name .= "." . A_LoopField\r
+ Continue\r
+ }\r
+ If A_LoopField!=\r
+ pdsp:= COM_Invoke(pdsp,name,prmn!="" ? prmn:"vT_NoNe")+COM_Release(pdsp)*0,name:=A_LoopField\r
+ Else Return prmn!="" ? COM_Invoke(pdsp,name,prmn,prm0,prm1,prm2,prm3,prm4,prm5,prm6,prm7,prm8):COM_Invoke(pdsp,name,prm0,prm1,prm2,prm3,prm4,prm5,prm6,prm7,prm8,prm9),COM_Release(pdsp)\r
+ }\r
+ }\r
+ sParams := "0123456789"\r
+ Loop, Parse, sParams\r
+ If (prm%A_LoopField% == "vT_NoNe")\r
+ {\r
+ sParams := SubStr(sParams,1,A_Index-1)\r
+ Break\r
+ }\r
+ VarSetCapacity(varg,16*nParams:=StrLen(sParams),0), VarSetCapacity(DispParams,16,0), VarSetCapacity(varResult,32,0), VarSetCapacity(ExcepInfo,32,0)\r
+ Loop, Parse, sParams\r
+; If prm%A_LoopField%+0=="" || InStr(prm%A_LoopField%,".") || prm%A_LoopField%>=0x80000000 || prm%A_LoopField%<-0x80000000\r
+ If prm%A_LoopField% is not integer\r
+ NumPut(COM_SysAllocString(prm%A_LoopField%),NumPut(8,varg,(nParams-A_Index)*16),4)\r
+ Else NumPut(SubStr(prm%A_LoopField%,1,1)="+" ? 9:prm%A_LoopField%=="-0" ? (prm%A_LoopField%:=0x80020004)*0+10:3,NumPut(prm%A_LoopField%,varg,(nParams-A_Index)*16+8),-12,"Ushort")\r
+ If nParams\r
+ NumPut(nParams,NumPut(&varg,DispParams),4)\r
+ If (nvk := SubStr(name,0)="=" ? 12:3)=12\r
+ name := SubStr(name,1,-1),NumPut(1,NumPut(NumPut(-3,varResult,4)-4,DispParams,4),4)\r
+ Global COM_HR, COM_LR:=""\r
+ If (COM_HR:=DllCall(NumGet(NumGet(1*pdsp)+20),"Uint",pdsp,"Uint",&varResult+16,"UintP",COM_Unicode4Ansi(wname,name),"Uint",1,"Uint",LCID,"intP",dispID,"Uint"))=0&&(COM_HR:=DllCall(NumGet(NumGet(1*pdsp)+24),"Uint",pdsp,"int",dispID,"Uint",&varResult+16,"Uint",LCID,"Ushort",nvk,"Uint",&DispParams,"Uint",&varResult,"Uint",&ExcepInfo,"Uint",0,"Uint"))!=0&&nParams&&nvk!=12&&(COM_LR:=DllCall(NumGet(NumGet(1*pdsp)+24),"Uint",pdsp,"int",dispID,"Uint",&varResult+16,"Uint",LCID,"Ushort",12,"Uint",NumPut(1,NumPut(NumPut(-3,varResult,4)-4,DispParams,4),4)-16,"Uint",0,"Uint",0,"Uint",0,"Uint"))=0\r
+ COM_HR:=0\r
+ Loop, % nParams\r
+ NumGet(varg,(A_Index-1)*16,"Ushort")=8 ? COM_SysFreeString(NumGet(varg,(A_Index-1)*16+8)) : ""\r
+ Global COM_VT := NumGet(varResult,0,"Ushort")\r
+ Return COM_HR=0 ? COM_VT>1 ? COM_VT=8||COM_VT<0x1000&&DllCall("oleaut32\VariantChangeTypeEx","Uint",&varResult,"Uint",&varResult,"Uint",LCID,"Ushort",1,"Ushort",8)=0 ? COM_Ansi4Unicode(bstr:=NumGet(varResult,8)) . COM_SysFreeString(bstr):NumGet(varResult,8):"":COM_Error(COM_HR,COM_LR,&ExcepInfo,name)\r
+}\r
+\r
+COM_Invoke_(pdsp,name,typ0="",prm0="",typ1="",prm1="",typ2="",prm2="",typ3="",prm3="",typ4="",prm4="",typ5="",prm5="",typ6="",prm6="",typ7="",prm7="",typ8="",prm8="",typ9="",prm9="")\r
+{\r
+ If name contains .\r
+ {\r
+ SubStr(name,1,1)!="." ? name.=".":name:=SubStr(name,2) . ".", COM_AddRef(pdsp)\r
+ Loop, Parse, name, .\r
+ {\r
+ If A_Index=1\r
+ {\r
+ name := A_LoopField\r
+ Continue\r
+ }\r
+ Else If name not contains [,(\r
+ prmn := ""\r
+ Else If InStr("])",SubStr(name,0))\r
+ Loop, Parse, name, [(,'")]\r
+ If A_Index=1\r
+ name := A_LoopField\r
+ Else prmn := A_LoopField\r
+ Else\r
+ {\r
+ name .= "." . A_LoopField\r
+ Continue\r
+ }\r
+ If A_LoopField!=\r
+ pdsp:= COM_Invoke(pdsp,name,prmn!="" ? prmn:"vT_NoNe")+COM_Release(pdsp)*0,name:=A_LoopField\r
+ Else Return COM_Invoke_(pdsp,name,typ0,prm0,typ1,prm1,typ2,prm2,typ3,prm3,typ4,prm4,typ5,prm5,typ6,prm6,typ7,prm7,typ8,prm8,typ9,prm9),COM_Release(pdsp)\r
+ }\r
+ }\r
+ sParams := "0123456789"\r
+ Loop, Parse, sParams\r
+ If (typ%A_LoopField% = "")\r
+ {\r
+ sParams := SubStr(sParams,1,A_Index-1)\r
+ Break\r
+ }\r
+ VarSetCapacity(varg,16*nParams:=StrLen(sParams),0), VarSetCapacity(DispParams,16,0), VarSetCapacity(varResult,32,0), VarSetCapacity(ExcepInfo,32,0)\r
+ Loop, Parse, sParams\r
+ NumPut(typ%A_LoopField%,varg,(nParams-A_Index)*16,"Ushort"),typ%A_LoopField%&0x4000=0 ? NumPut(typ%A_LoopField%=8 ? COM_SysAllocString(prm%A_LoopField%):prm%A_LoopField%,varg,(nParams-A_Index)*16+8,typ%A_LoopField%=5||typ%A_LoopField%=7 ? "double":typ%A_LoopField%=4 ? "float":"int64"):typ%A_LoopField%=0x400C||typ%A_LoopField%=0x400E ? NumPut(prm%A_LoopField%,varg,(nParams-A_Index)*16+8):(VarSetCapacity(_ref_%A_LoopField%,8,0),NumPut(&_ref_%A_LoopField%,varg,(nParams-A_Index)*16+8),NumPut((prmx:=prm%A_LoopField%)&&typ%A_LoopField%=0x4008 ? COM_SysAllocString(%prmx%):%prmx%,_ref_%A_LoopField%,0,typ%A_LoopField%=0x4005||typ%A_LoopField%=0x4007 ? "double":typ%A_LoopField%=0x4004 ? "float":"int64"))\r
+ If nParams\r
+ NumPut(nParams,NumPut(&varg,DispParams),4)\r
+ If (nvk := SubStr(name,0)="=" ? 12:3)=12\r
+ name := SubStr(name,1,-1),NumPut(1,NumPut(NumPut(-3,varResult,4)-4,DispParams,4),4)\r
+ Global COM_HR, COM_LR:=""\r
+ If (COM_HR:=DllCall(NumGet(NumGet(1*pdsp)+20),"Uint",pdsp,"Uint",&varResult+16,"UintP",COM_Unicode4Ansi(wname,name),"Uint",1,"Uint",LCID,"intP",dispID,"Uint"))=0&&(COM_HR:=DllCall(NumGet(NumGet(1*pdsp)+24),"Uint",pdsp,"int",dispID,"Uint",&varResult+16,"Uint",LCID,"Ushort",nvk,"Uint",&DispParams,"Uint",&varResult,"Uint",&ExcepInfo,"Uint",0,"Uint"))!=0&&nParams&&nvk!=12&&(COM_LR:=DllCall(NumGet(NumGet(1*pdsp)+24),"Uint",pdsp,"int",dispID,"Uint",&varResult+16,"Uint",LCID,"Ushort",12,"Uint",NumPut(1,NumPut(NumPut(-3,varResult,4)-4,DispParams,4),4)-16,"Uint",0,"Uint",0,"Uint",0,"Uint"))=0\r
+ COM_HR:=0\r
+ Loop, Parse, sParams\r
+ typ%A_LoopField%&0x4000=0 ? (typ%A_LoopField%=8 ? COM_SysFreeString(NumGet(varg,(nParams-A_Index)*16+8)):""):typ%A_LoopField%=0x400C||typ%A_LoopField%=0x400E ? "":(prmx:=prm%A_LoopField%,%prmx%:=typ%A_LoopField%=0x4008 ? COM_Ansi4Unicode(prmx:=NumGet(_ref_%A_LoopField%)) . COM_SysFreeString(prmx):NumGet(_ref_%A_LoopField%,0,typ%A_LoopField%=0x4005||typ%A_LoopField%=0x4007 ? "double":typ%A_LoopField%=0x4004 ? "float":"int64"))\r
+ Global COM_VT := NumGet(varResult,0,"Ushort")\r
+ Return COM_HR=0 ? COM_VT>1 ? COM_VT=8||COM_VT<0x1000&&DllCall("oleaut32\VariantChangeTypeEx","Uint",&varResult,"Uint",&varResult,"Uint",LCID,"Ushort",1,"Ushort",8)=0 ? COM_Ansi4Unicode(bstr:=NumGet(varResult,8)) . COM_SysFreeString(bstr):NumGet(varResult,8):"":COM_Error(COM_HR,COM_LR,&ExcepInfo,name)\r
+}\r
+\r
+COM_DispInterface(this, prm1="", prm2="", prm3="", prm4="", prm5="", prm6="", prm7="", prm8="")\r
+{\r
+ Critical\r
+ If A_EventInfo = 6\r
+ hr:=DllCall(NumGet(NumGet(0+p:=NumGet(this+8))+28),"Uint",p,"Uint",prm1,"UintP",pname,"Uint",1,"UintP",0), hr==0 ? (VarSetCapacity(sfn,63),DllCall("user32\wsprintfA","str",sfn,"str","%s%S","Uint",this+40,"Uint",pname,"Cdecl"),COM_SysFreeString(pname),%sfn%(prm5,this,prm6)):""\r
+ Else If A_EventInfo = 5\r
+ hr:=DllCall(NumGet(NumGet(0+p:=NumGet(this+8))+40),"Uint",p,"Uint",prm2,"Uint",prm3,"Uint",prm5)\r
+ Else If A_EventInfo = 4\r
+ NumPut(0*hr:=0x80004001,prm3+0)\r
+ Else If A_EventInfo = 3\r
+ NumPut(0,prm1+0)\r
+ Else If A_EventInfo = 2\r
+ NumPut(hr:=NumGet(this+4)-1,this+4)\r
+ Else If A_EventInfo = 1\r
+ NumPut(hr:=NumGet(this+4)+1,this+4)\r
+ Else If A_EventInfo = 0\r
+ COM_IsEqualGUID(this+24,prm1)||InStr("{00020400-0000-0000-C000-000000000046}{00000000-0000-0000-C000-000000000046}",COM_String4GUID(prm1)) ? NumPut(NumPut(NumGet(this+4)+1,this+4)-8,prm2+0):NumPut(0*hr:=0x80004002,prm2+0)\r
+ Return hr\r
+}\r
+\r
+COM_DispGetParam(pDispParams, Position = 0, vt = 8)\r
+{\r
+ VarSetCapacity(varResult,16,0)\r
+ DllCall("oleaut32\DispGetParam", "Uint", pDispParams, "Uint", Position, "Ushort", vt, "Uint", &varResult, "UintP", nArgErr)\r
+ Return NumGet(varResult,0,"Ushort")=8 ? COM_Ansi4Unicode(NumGet(varResult,8)) . COM_SysFreeString(NumGet(varResult,8)) : NumGet(varResult,8)\r
+}\r
+\r
+COM_DispSetParam(val, pDispParams, Position = 0, vt = 8)\r
+{\r
+ Return NumPut(vt=8 ? COM_SysAllocString(val) : val,NumGet(NumGet(pDispParams+0)+(NumGet(pDispParams+8)-Position)*16-8),0,vt=11||vt=2 ? "short" : "int")\r
+}\r
+\r
+COM_Error(hr = "", lr = "", pei = "", name = "")\r
+{\r
+ Static bDebug:=1\r
+ If Not pei\r
+ {\r
+ bDebug:=hr\r
+ Global COM_HR, COM_LR\r
+ Return COM_HR&&COM_LR ? COM_LR<<32|COM_HR:COM_HR\r
+ }\r
+ Else If !bDebug\r
+ Return\r
+ hr ? (VarSetCapacity(sError,1023),VarSetCapacity(nError,10),DllCall("kernel32\FormatMessageA","Uint",0x1000,"Uint",0,"Uint",hr<>0x80020009 ? hr : (bExcep:=1)*(hr:=NumGet(pei+28)) ? hr : hr:=NumGet(pei+0,0,"Ushort")+0x80040200,"Uint",0,"str",sError,"Uint",1024,"Uint",0),DllCall("user32\wsprintfA","str",nError,"str","0x%08X","Uint",hr,"Cdecl")) : sError:="The COM Object may not be a valid Dispatch Object!`n`tFirst ensure that COM Library has been initialized through COM_Init().`n", lr ? (VarSetCapacity(sError2,1023),VarSetCapacity(nError2,10),DllCall("kernel32\FormatMessageA","Uint",0x1000,"Uint",0,"Uint",lr,"Uint",0,"str",sError2,"Uint",1024,"Uint",0),DllCall("user32\wsprintfA","str",nError2,"str","0x%08X","Uint",lr,"Cdecl")) : ""\r
+ MsgBox, 260, COM Error Notification, % "Function Name:`t""" . name . """`nERROR:`t" . sError . "`t(" . nError . ")" . (bExcep ? SubStr(NumGet(pei+24) ? DllCall(NumGet(pei+24),"Uint",pei) : "",1,0) . "`nPROG:`t" . COM_Ansi4Unicode(NumGet(pei+4)) . COM_SysFreeString(NumGet(pei+4)) . "`nDESC:`t" . COM_Ansi4Unicode(NumGet(pei+8)) . COM_SysFreeString(NumGet(pei+8)) . "`nHELP:`t" . COM_Ansi4Unicode(NumGet(pei+12)) . COM_SysFreeString(NumGet(pei+12)) . "," . NumGet(pei+16) : "") . (lr ? "`n`nERROR2:`t" . sError2 . "`t(" . nError2 . ")" : "") . "`n`nWill Continue?"\r
+ IfMsgBox, No, Exit\r
+}\r
+\r
+COM_CreateIDispatch()\r
+{\r
+ Static IDispatch\r
+ If Not VarSetCapacity(IDispatch)\r
+ {\r
+ VarSetCapacity(IDispatch,28,0), nParams=3112469\r
+ Loop, Parse, nParams\r
+ NumPut(RegisterCallback("COM_DispInterface","",A_LoopField,A_Index-1),IDispatch,4*(A_Index-1))\r
+ }\r
+ Return &IDispatch\r
+}\r
+\r
+COM_GetDefaultInterface(pdisp, LCID = 0)\r
+{\r
+ DllCall(NumGet(NumGet(1*pdisp) +12), "Uint", pdisp , "UintP", ctinf)\r
+ If ctinf\r
+ {\r
+ DllCall(NumGet(NumGet(1*pdisp)+16), "Uint", pdisp, "Uint" , 0, "Uint", LCID, "UintP", ptinf)\r
+ DllCall(NumGet(NumGet(1*ptinf)+12), "Uint", ptinf, "UintP", pattr)\r
+ DllCall(NumGet(NumGet(1*pdisp)+ 0), "Uint", pdisp, "Uint" , pattr, "UintP", ppv)\r
+ DllCall(NumGet(NumGet(1*ptinf)+76), "Uint", ptinf, "Uint" , pattr)\r
+ DllCall(NumGet(NumGet(1*ptinf)+ 8), "Uint", ptinf)\r
+ If ppv\r
+ DllCall(NumGet(NumGet(1*pdisp)+ 8), "Uint", pdisp), pdisp := ppv\r
+ }\r
+ Return pdisp\r
+}\r
+\r
+COM_GetDefaultEvents(pdisp, LCID = 0)\r
+{\r
+ DllCall(NumGet(NumGet(1*pdisp)+16), "Uint", pdisp, "Uint" , 0, "Uint", LCID, "UintP", ptinf)\r
+ DllCall(NumGet(NumGet(1*ptinf)+12), "Uint", ptinf, "UintP", pattr)\r
+ VarSetCapacity(IID,16), DllCall("RtlMoveMemory", "Uint", &IID, "Uint", pattr, "Uint", 16)\r
+ DllCall(NumGet(NumGet(1*ptinf)+76), "Uint", ptinf, "Uint" , pattr)\r
+ DllCall(NumGet(NumGet(1*ptinf)+72), "Uint", ptinf, "UintP", ptlib, "UintP", idx)\r
+ DllCall(NumGet(NumGet(1*ptinf)+ 8), "Uint", ptinf)\r
+ Loop, % DllCall(NumGet(NumGet(1*ptlib)+12), "Uint", ptlib)\r
+ {\r
+ DllCall(NumGet(NumGet(1*ptlib)+20), "Uint", ptlib, "Uint", A_Index-1, "UintP", TKind)\r
+ If TKind <> 5\r
+ Continue\r
+ DllCall(NumGet(NumGet(1*ptlib)+16), "Uint", ptlib, "Uint", A_Index-1, "UintP", ptinf)\r
+ DllCall(NumGet(NumGet(1*ptinf)+12), "Uint", ptinf, "UintP", pattr)\r
+ nCount:=NumGet(pattr+48,0,"Ushort")\r
+ DllCall(NumGet(NumGet(1*ptinf)+76), "Uint", ptinf, "Uint" , pattr)\r
+ Loop, % nCount\r
+ {\r
+ DllCall(NumGet(NumGet(1*ptinf)+36), "Uint", ptinf, "Uint", A_Index-1, "UintP", nFlags)\r
+ If !(nFlags & 1)\r
+ Continue\r
+ DllCall(NumGet(NumGet(1*ptinf)+32), "Uint", ptinf, "Uint", A_Index-1, "UintP", hRefType)\r
+ DllCall(NumGet(NumGet(1*ptinf)+56), "Uint", ptinf, "Uint", hRefType , "UintP", prinf)\r
+ DllCall(NumGet(NumGet(1*prinf)+12), "Uint", prinf, "UintP", pattr)\r
+ nFlags & 2 ? DIID:=COM_String4GUID(pattr) : bFind:=COM_IsEqualGUID(pattr,&IID)\r
+ DllCall(NumGet(NumGet(1*prinf)+76), "Uint", prinf, "Uint" , pattr)\r
+ DllCall(NumGet(NumGet(1*prinf)+ 8), "Uint", prinf)\r
+ }\r
+ DllCall(NumGet(NumGet(1*ptinf)+ 8), "Uint", ptinf)\r
+ If bFind\r
+ Break\r
+ }\r
+ DllCall(NumGet(NumGet(1*ptlib)+ 8), "Uint", ptlib)\r
+ Return bFind ? DIID : "{00000000-0000-0000-0000-000000000000}"\r
+}\r
+\r
+COM_GetGuidOfName(pdisp, Name, LCID = 0)\r
+{\r
+ DllCall(NumGet(NumGet(1*pdisp)+16), "Uint", pdisp, "Uint", 0, "Uint", LCID, "UintP", ptinf)\r
+ DllCall(NumGet(NumGet(1*ptinf)+72), "Uint", ptinf, "UintP", ptlib, "UintP", idx)\r
+ DllCall(NumGet(NumGet(1*ptinf)+ 8), "Uint", ptinf), ptinf:=0\r
+ DllCall(NumGet(NumGet(1*ptlib)+44), "Uint", ptlib, "Uint", COM_Unicode4Ansi(Name,Name), "Uint", 0, "UintP", ptinf, "UintP", memID, "UshortP", 1)\r
+ DllCall(NumGet(NumGet(1*ptlib)+ 8), "Uint", ptlib)\r
+ DllCall(NumGet(NumGet(1*ptinf)+12), "Uint", ptinf, "UintP", pattr)\r
+ GUID := COM_String4GUID(pattr)\r
+ DllCall(NumGet(NumGet(1*ptinf)+76), "Uint", ptinf, "Uint" , pattr)\r
+ DllCall(NumGet(NumGet(1*ptinf)+ 8), "Uint", ptinf)\r
+ Return GUID\r
+}\r
+\r
+COM_GetTypeInfoOfGuid(pdisp, GUID, LCID = 0)\r
+{\r
+ DllCall(NumGet(NumGet(1*pdisp)+16), "Uint", pdisp, "Uint", 0, "Uint", LCID, "UintP", ptinf)\r
+ DllCall(NumGet(NumGet(1*ptinf)+72), "Uint", ptinf, "UintP", ptlib, "UintP", idx)\r
+ DllCall(NumGet(NumGet(1*ptinf)+ 8), "Uint", ptinf), ptinf := 0\r
+ DllCall(NumGet(NumGet(1*ptlib)+24), "Uint", ptlib, "Uint", COM_GUID4String(GUID,GUID), "UintP", ptinf)\r
+ DllCall(NumGet(NumGet(1*ptlib)+ 8), "Uint", ptlib)\r
+ Return ptinf\r
+}\r
+\r
+; A Function Name including Prefix is limited to 63 bytes!\r
+COM_ConnectObject(psource, prefix = "", DIID = "")\r
+{\r
+ If Not DIID\r
+ 0+(pconn:=COM_FindConnectionPoint(psource,"{00020400-0000-0000-C000-000000000046}")) ? (DIID:=COM_GetConnectionInterface(pconn))="{00020400-0000-0000-C000-000000000046}" ? DIID:=COM_GetDefaultEvents(psource) : "" : pconn:=COM_FindConnectionPoint(psource,DIID:=COM_GetDefaultEvents(psource))\r
+ Else pconn:=COM_FindConnectionPoint(psource,SubStr(DIID,1,1)="{" ? DIID : DIID:=COM_GetGuidOfName(psource,DIID))\r
+ If !pconn || !ptinf:=COM_GetTypeInfoOfGuid(psource,DIID)\r
+ {\r
+ MsgBox, No Event Interface Exists!\r
+ Return\r
+ }\r
+ psink:=COM_CoTaskMemAlloc(40+StrLen(prefix)+1), NumPut(1,NumPut(COM_CreateIDispatch(),psink+0)), NumPut(psource,NumPut(ptinf,psink+8))\r
+ DllCall("RtlMoveMemory", "Uint", psink+24, "Uint", COM_GUID4String(DIID,DIID), "Uint", 16)\r
+ DllCall("RtlMoveMemory", "Uint", psink+40, "Uint", &prefix, "Uint", StrLen(prefix)+1)\r
+ NumPut(COM_Advise(pconn,psink),NumPut(pconn,psink+16))\r
+ Return psink\r
+}\r
+\r
+COM_DisconnectObject(psink)\r
+{\r
+ Return COM_Unadvise(NumGet(psink+16),NumGet(psink+20))=0 ? (0,COM_Release(NumGet(psink+16)),COM_Release(NumGet(psink+8)),COM_CoTaskMemFree(psink)) : 1\r
+}\r
+\r
+COM_CreateObject(CLSID, IID = "", CLSCTX = 5)\r
+{\r
+ DllCall("ole32\CoCreateInstance", "Uint", SubStr(CLSID,1,1)="{" ? COM_GUID4String(CLSID,CLSID) : COM_CLSID4ProgID(CLSID,CLSID), "Uint", 0, "Uint", CLSCTX, "Uint", COM_GUID4String(IID,IID ? IID : IID=0 ? "{00000000-0000-0000-C000-000000000046}" : "{00020400-0000-0000-C000-000000000046}"), "UintP", ppv)\r
+ Return ppv\r
+}\r
+\r
+COM_ActiveXObject(ProgID)\r
+{\r
+ DllCall("ole32\CoCreateInstance", "Uint", SubStr(ProgID,1,1)="{" ? COM_GUID4String(ProgID,ProgID) : COM_CLSID4ProgID(ProgID,ProgID), "Uint", 0, "Uint", 5, "Uint", COM_GUID4String(IID_IDispatch,"{00020400-0000-0000-C000-000000000046}"), "UintP", pdisp)\r
+ Return COM_GetDefaultInterface(pdisp)\r
+}\r
+\r
+COM_GetObject(Moniker)\r
+{\r
+ DllCall("ole32\CoGetObject", "Uint", COM_Unicode4Ansi(Moniker,Moniker), "Uint", 0, "Uint", COM_GUID4String(IID_IDispatch,"{00020400-0000-0000-C000-000000000046}"), "UintP", pdisp)\r
+ Return COM_GetDefaultInterface(pdisp)\r
+}\r
+\r
+COM_GetActiveObject(ProgID)\r
+{\r
+ DllCall("oleaut32\GetActiveObject", "Uint", SubStr(ProgID,1,1)="{" ? COM_GUID4String(ProgID,ProgID) : COM_CLSID4ProgID(ProgID,ProgID), "Uint", 0, "UintP", punk)\r
+ DllCall(NumGet(NumGet(1*punk)+0), "Uint", punk, "Uint", COM_GUID4String(IID_IDispatch,"{00020400-0000-0000-C000-000000000046}"), "UintP", pdisp)\r
+ DllCall(NumGet(NumGet(1*punk)+8), "Uint", punk)\r
+ Return COM_GetDefaultInterface(pdisp)\r
+}\r
+\r
+COM_CLSID4ProgID(ByRef CLSID, ProgID)\r
+{\r
+ VarSetCapacity(CLSID, 16)\r
+ DllCall("ole32\CLSIDFromProgID", "Uint", COM_Unicode4Ansi(ProgID,ProgID), "Uint", &CLSID)\r
+ Return &CLSID\r
+}\r
+\r
+COM_GUID4String(ByRef CLSID, String)\r
+{\r
+ VarSetCapacity(CLSID, 16)\r
+ DllCall("ole32\CLSIDFromString", "Uint", COM_Unicode4Ansi(String,String,38), "Uint", &CLSID)\r
+ Return &CLSID\r
+}\r
+\r
+COM_ProgID4CLSID(pCLSID)\r
+{\r
+ DllCall("ole32\ProgIDFromCLSID", "Uint", pCLSID, "UintP", pProgID)\r
+ Return COM_Ansi4Unicode(pProgID) . COM_CoTaskMemFree(pProgID)\r
+}\r
+\r
+COM_String4GUID(pGUID)\r
+{\r
+ VarSetCapacity(String, 38 * 2 + 1)\r
+ DllCall("ole32\StringFromGUID2", "Uint", pGUID, "Uint", &String, "int", 39)\r
+ Return COM_Ansi4Unicode(&String, 38)\r
+}\r
+\r
+COM_IsEqualGUID(pGUID1, pGUID2)\r
+{\r
+ Return DllCall("ole32\IsEqualGUID", "Uint", pGUID1, "Uint", pGUID2)\r
+}\r
+\r
+COM_CoCreateGuid()\r
+{\r
+ VarSetCapacity(GUID, 16, 0)\r
+ DllCall("ole32\CoCreateGuid", "Uint", &GUID)\r
+ Return COM_String4GUID(&GUID)\r
+}\r
+\r
+COM_CoTaskMemAlloc(cb)\r
+{\r
+ Return DllCall("ole32\CoTaskMemAlloc", "Uint", cb)\r
+}\r
+\r
+COM_CoTaskMemFree(pv)\r
+{\r
+ DllCall("ole32\CoTaskMemFree", "Uint", pv)\r
+}\r
+\r
+COM_CoInitialize()\r
+{\r
+ Return DllCall("ole32\CoInitialize", "Uint", 0)\r
+}\r
+\r
+COM_CoUninitialize()\r
+{\r
+ DllCall("ole32\CoUninitialize")\r
+}\r
+\r
+COM_SysAllocString(sString)\r
+{\r
+ Return DllCall("oleaut32\SysAllocString", "Uint", COM_Ansi2Unicode(sString,wString))\r
+}\r
+\r
+COM_SysFreeString(bstr)\r
+{\r
+ DllCall("oleaut32\SysFreeString", "Uint", bstr)\r
+}\r
+\r
+COM_SysStringLen(bstr)\r
+{\r
+ Return DllCall("oleaut32\SysStringLen", "Uint", bstr)\r
+}\r
+\r
+COM_SafeArrayDestroy(psa)\r
+{\r
+ Return DllCall("oleaut32\SafeArrayDestroy", "Uint", psa)\r
+}\r
+\r
+COM_VariantClear(pvarg)\r
+{\r
+ Return DllCall("oleaut32\VariantClear", "Uint", pvarg)\r
+}\r
+\r
+COM_AccInit()\r
+{\r
+ COM_Init()\r
+ If Not DllCall("GetModuleHandle", "str", "oleacc")\r
+ Return DllCall("LoadLibrary", "str", "oleacc")\r
+}\r
+\r
+COM_AccTerm()\r
+{\r
+ COM_Term()\r
+ If h:= DllCall("GetModuleHandle", "str", "oleacc")\r
+ Return DllCall("FreeLibrary", "Uint", h)\r
+}\r
+\r
+COM_AccessibleChildren(pacc, cChildren, ByRef varChildren)\r
+{\r
+ VarSetCapacity(varChildren,cChildren*16,0)\r
+ If DllCall("oleacc\AccessibleChildren", "Uint", pacc, "Uint", 0, "Uint", cChildren+0, "Uint", &varChildren, "UintP", cChildren:=0)=0\r
+ Return cChildren\r
+}\r
+\r
+COM_AccessibleObjectFromEvent(hWnd, idObject, idChild, ByRef _idChild_="")\r
+{\r
+ VarSetCapacity(varChild,16,0)\r
+ If DllCall("oleacc\AccessibleObjectFromEvent", "Uint", hWnd, "Uint", idObject, "Uint", idChild, "UintP", pacc, "Uint", &varChild)=0\r
+ Return pacc, _idChild_:=NumGet(varChild,8)\r
+}\r
+\r
+COM_AccessibleObjectFromPoint(x, y, ByRef _idChild_="")\r
+{\r
+ VarSetCapacity(varChild,16,0)\r
+ If DllCall("oleacc\AccessibleObjectFromPoint", "int", x, "int", y, "UintP", pacc, "Uint", &varChild)=0\r
+ Return pacc, _idChild_:=NumGet(varChild,8)\r
+}\r
+\r
+COM_AccessibleObjectFromWindow(hWnd, idObject=-4, IID = "")\r
+{\r
+ If DllCall("oleacc\AccessibleObjectFromWindow", "Uint", hWnd, "Uint", idObject, "Uint", COM_GUID4String(IID, IID ? IID : idObject&0xFFFFFFFF==0xFFFFFFF0 ? "{00020400-0000-0000-C000-000000000046}":"{618736E0-3C3D-11CF-810C-00AA00389B71}"), "UintP", pacc)=0\r
+ Return pacc\r
+}\r
+\r
+COM_WindowFromAccessibleObject(pacc)\r
+{\r
+ If DllCall("oleacc\WindowFromAccessibleObject", "Uint", pacc, "UintP", hWnd)=0\r
+ Return hWnd\r
+}\r
+\r
+COM_GetRoleText(nRole)\r
+{\r
+ nSize:= DllCall("oleacc\GetRoleTextA", "Uint", nRole, "Uint", 0, "Uint", 0)\r
+ VarSetCapacity(sRole,nSize)\r
+ If DllCall("oleacc\GetRoleTextA", "Uint", nRole, "str", sRole, "Uint", nSize+1)\r
+ Return sRole\r
+}\r
+\r
+COM_GetStateText(nState)\r
+{\r
+ nSize:= DllCall("oleacc\GetStateTextA", "Uint", nState, "Uint", 0, "Uint", 0)\r
+ VarSetCapacity(sState,nSize)\r
+ If DllCall("oleacc\GetStateTextA", "Uint", nState, "str", sState, "Uint", nSize+1)\r
+ Return sState\r
+}\r
+\r
+COM_AtlAxWinInit(Version = "")\r
+{\r
+ COM_Init()\r
+ If Not DllCall("GetModuleHandle", "str", "atl" . Version)\r
+ DllCall("LoadLibrary", "str", "atl" . Version)\r
+ Return DllCall("atl" . Version . "\AtlAxWinInit")\r
+}\r
+\r
+COM_AtlAxWinTerm(Version = "")\r
+{\r
+ COM_Term()\r
+ If h:= DllCall("GetModuleHandle", "str", "atl" . Version)\r
+ Return DllCall("FreeLibrary", "Uint", h)\r
+}\r
+\r
+COM_AtlAxAttachControl(pdsp, hWnd, Version = "")\r
+{\r
+ Return DllCall("atl" . Version . "\AtlAxAttachControl", "Uint", punk:=COM_QueryInterface(pdsp,0), "Uint", hWnd, "Uint", 0), COM_Release(punk)\r
+}\r
+\r
+COM_AtlAxCreateControl(hWnd, Name, Version = "")\r
+{\r
+ If DllCall("atl" . Version . "\AtlAxCreateControl", "Uint", COM_Unicode4Ansi(Name,Name), "Uint", hWnd, "Uint", 0, "Uint", 0)=0\r
+ Return COM_AtlAxGetControl(hWnd, Version)\r
+}\r
+\r
+COM_AtlAxGetControl(hWnd, Version = "")\r
+{\r
+ If DllCall("atl" . Version . "\AtlAxGetControl", "Uint", hWnd, "UintP", punk)=0\r
+ pdsp:=COM_QueryInterface(punk), COM_Release(punk)\r
+ Return pdsp\r
+}\r
+\r
+COM_AtlAxGetHost(hWnd, Version = "")\r
+{\r
+ If DllCall("atl" . Version . "\AtlAxGetHost", "Uint", hWnd, "UintP", punk)=0\r
+ pdsp:=COM_QueryInterface(punk), COM_Release(punk)\r
+ Return pdsp\r
+}\r
+\r
+COM_AtlAxCreateContainer(hWnd, l, t, w, h, Name = "", Version = "")\r
+{\r
+ Return DllCall("CreateWindowEx", "Uint",0x200, "str", "AtlAxWin" . Version, "Uint", Name ? &Name : 0, "Uint", 0x54000000, "int", l, "int", t, "int", w, "int", h, "Uint", hWnd, "Uint", 0, "Uint", 0, "Uint", 0)\r
+}\r
+\r
+COM_AtlAxGetContainer(pdsp, bCtrl = "")\r
+{\r
+ DllCall(NumGet(NumGet(1*pdsp)+ 0), "Uint", pdsp, "Uint", COM_GUID4String(IID_IOleWindow,"{00000114-0000-0000-C000-000000000046}"), "UintP", pwin)\r
+ DllCall(NumGet(NumGet(1*pwin)+12), "Uint", pwin, "UintP", hCtrl)\r
+ DllCall(NumGet(NumGet(1*pwin)+ 8), "Uint", pwin)\r
+ Return bCtrl ? hCtrl : DllCall("GetParent", "Uint", hCtrl)\r
+}\r
+\r
+COM_Ansi4Unicode(pString, nSize = "")\r
+{\r
+ If (nSize = "")\r
+ nSize:=DllCall("kernel32\WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "Uint", 0, "int", 0, "Uint", 0, "Uint", 0)\r
+ VarSetCapacity(sString, nSize)\r
+ DllCall("kernel32\WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "str", sString, "int", nSize + 1, "Uint", 0, "Uint", 0)\r
+ Return sString\r
+}\r
+\r
+COM_Unicode4Ansi(ByRef wString, sString, nSize = "")\r
+{\r
+ If (nSize = "")\r
+ nSize:=DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0)\r
+ VarSetCapacity(wString, nSize * 2 + 1)\r
+ DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize + 1)\r
+ Return &wString\r
+}\r
+\r
+COM_Ansi2Unicode(ByRef sString, ByRef wString, nSize = "")\r
+{\r
+ If (nSize = "")\r
+ nSize:=DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0)\r
+ VarSetCapacity(wString, nSize * 2 + 1)\r
+ DllCall("kernel32\MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize + 1)\r
+ Return &wString\r
+}\r
+\r
+COM_Unicode2Ansi(ByRef wString, ByRef sString, nSize = "")\r
+{\r
+ pString := wString + 0 > 65535 ? wString : &wString\r
+ If (nSize = "")\r
+ nSize:=DllCall("kernel32\WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "Uint", 0, "int", 0, "Uint", 0, "Uint", 0)\r
+ VarSetCapacity(sString, nSize)\r
+ DllCall("kernel32\WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "str", sString, "int", nSize + 1, "Uint", 0, "Uint", 0)\r
+ Return &sString\r
+}\r
+\r
+COM_ScriptControl(sCode, sLang = "", bEval = False, sFunc = "", sName = "", pdisp = 0, bGlobal = False)\r
+{\r
+ COM_Init()\r
+ psc := COM_CreateObject("MSScriptControl.ScriptControl")\r
+ COM_Invoke(psc, "Language", sLang ? sLang : "VBScript")\r
+ sName ? COM_Invoke(psc, "AddObject", sName, "+" . pdisp, bGlobal) : ""\r
+ sFunc ? COM_Invoke(psc, "AddCode", sCode) : ""\r
+ ret := COM_Invoke(psc, bEval ? "Eval" : "ExecuteStatement", sFunc ? sFunc : sCode)\r
+ COM_Release(psc)\r
+ COM_Term()\r
+ Return ret\r
+}\r