DotNetAll.au3 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. #include-once
  2. ; ####################################################################################################
  3. ; ### ###
  4. ; ### Variant.au3 ###
  5. ; ### ###
  6. ; ####################################################################################################
  7. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  8. ; Copied from AutoItObject.au3 by the AutoItObject-Team: monoceres, trancexx, Kip, ProgAndy
  9. ; https://www.autoitscript.com/forum/index.php?showtopic=110379
  10. Global Const $tagVARIANT = "word vt;word r1;word r2;word r3;ptr data; ptr"
  11. ; The structure takes up 16/24 bytes when running 32/64 bit
  12. ; Space for the data element at the end represents 2 pointers
  13. ; This is 8 bytes running 32 bit and 16 bytes running 64 bit
  14. Global Const $VT_EMPTY = 0 ; 0x0000
  15. Global Const $VT_NULL = 1 ; 0x0001
  16. Global Const $VT_I2 = 2 ; 0x0002
  17. Global Const $VT_I4 = 3 ; 0x0003
  18. Global Const $VT_R4 = 4 ; 0x0004
  19. Global Const $VT_R8 = 5 ; 0x0005
  20. Global Const $VT_CY = 6 ; 0x0006
  21. Global Const $VT_DATE = 7 ; 0x0007
  22. Global Const $VT_BSTR = 8 ; 0x0008
  23. Global Const $VT_DISPATCH = 9 ; 0x0009
  24. Global Const $VT_ERROR = 10 ; 0x000A
  25. Global Const $VT_BOOL = 11 ; 0x000B
  26. Global Const $VT_VARIANT = 12 ; 0x000C
  27. Global Const $VT_UNKNOWN = 13 ; 0x000D
  28. Global Const $VT_DECIMAL = 14 ; 0x000E
  29. Global Const $VT_I1 = 16 ; 0x0010
  30. Global Const $VT_UI1 = 17 ; 0x0011
  31. Global Const $VT_UI2 = 18 ; 0x0012
  32. Global Const $VT_UI4 = 19 ; 0x0013
  33. Global Const $VT_I8 = 20 ; 0x0014
  34. Global Const $VT_UI8 = 21 ; 0x0015
  35. Global Const $VT_INT = 22 ; 0x0016
  36. Global Const $VT_UINT = 23 ; 0x0017
  37. Global Const $VT_VOID = 24 ; 0x0018
  38. Global Const $VT_HRESULT = 25 ; 0x0019
  39. Global Const $VT_PTR = 26 ; 0x001A
  40. Global Const $VT_SAFEARRAY = 27 ; 0x001B
  41. Global Const $VT_CARRAY = 28 ; 0x001C
  42. Global Const $VT_USERDEFINED = 29 ; 0x001D
  43. Global Const $VT_LPSTR = 30 ; 0x001E
  44. Global Const $VT_LPWSTR = 31 ; 0x001F
  45. Global Const $VT_RECORD = 36 ; 0x0024
  46. Global Const $VT_INT_PTR = 37 ; 0x0025
  47. Global Const $VT_UINT_PTR = 38 ; 0x0026
  48. Global Const $VT_FILETIME = 64 ; 0x0040
  49. Global Const $VT_BLOB = 65 ; 0x0041
  50. Global Const $VT_STREAM = 66 ; 0x0042
  51. Global Const $VT_STORAGE = 67 ; 0x0043
  52. Global Const $VT_STREAMED_OBJECT = 68 ; 0x0044
  53. Global Const $VT_STORED_OBJECT = 69 ; 0x0045
  54. Global Const $VT_BLOB_OBJECT = 70 ; 0x0046
  55. Global Const $VT_CF = 71 ; 0x0047
  56. Global Const $VT_CLSID = 72 ; 0x0048
  57. Global Const $VT_VERSIONED_STREAM = 73 ; 0x0049
  58. Global Const $VT_BSTR_BLOB = 0xFFF
  59. Global Const $VT_VECTOR = 0x1000
  60. Global Const $VT_ARRAY = 0x2000
  61. Global Const $VT_BYREF = 0x4000
  62. Global Const $VT_RESERVED = 0x8000
  63. Global Const $VT_ILLEGAL = 0xFFFF
  64. Global Const $VT_ILLEGALMASKED = 0xFFF
  65. Global Const $VT_TYPEMASK = 0xFFF
  66. ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  67. ;Global Const $tagVARIANT = "word vt;word r1;word r2;word r3;ptr data; ptr"
  68. ; The structure takes up 16/24 bytes when running 32/64 bit
  69. ; Space for the data element at the end represents 2 pointers
  70. ; This is 8 bytes running 32 bit and 16 bytes running 64 bit
  71. #cs
  72. DECIMAL structure
  73. https://msdn.microsoft.com/en-us/library/windows/desktop/ms221061(v=vs.85).aspx
  74. From oledb.h:
  75. typedef struct tagDEC {
  76. USHORT wReserved; ; vt, 2 bytes
  77. union { ; r1, 2 bytes
  78. struct {
  79. BYTE scale;
  80. BYTE sign;
  81. };
  82. USHORT signscale;
  83. };
  84. ULONG Hi32; ; r2, r3, 4 bytes
  85. union { ; data, 8 bytes
  86. struct {
  87. #ifdef _MAC
  88. ULONG Mid32;
  89. ULONG Lo32;
  90. #else
  91. ULONG Lo32;
  92. ULONG Mid32;
  93. #endif
  94. };
  95. ULONGLONG Lo64;
  96. };
  97. } DECIMAL;
  98. #ce
  99. Global Const $tagDEC = "word wReserved;byte scale;byte sign;uint Hi32;uint Lo32;uint Mid32"
  100. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  101. ; Variant functions
  102. ; Copied from AutoItObject.au3 by the AutoItObject-Team: monoceres, trancexx, Kip, ProgAndy
  103. ; https://www.autoitscript.com/forum/index.php?showtopic=110379
  104. ; #FUNCTION# ====================================================================================================================
  105. ; Name...........: VariantClear
  106. ; Description ...: Clears the value of a variant
  107. ; Syntax.........: VariantClear($pvarg)
  108. ; Parameters ....: $pvarg - the VARIANT to clear
  109. ; Return values .: Success - 0
  110. ; Failure - nonzero
  111. ; Author ........: Prog@ndy
  112. ; Modified.......:
  113. ; Remarks .......:
  114. ; Related .......: VariantFree
  115. ; Link ..........: http://msdn.microsoft.com/en-us/library/ms221165.aspx
  116. ; Example .......:
  117. ; ===============================================================================================================================
  118. Func VariantClear($pvarg)
  119. ; Author: Prog@ndy
  120. Local $aCall = DllCall("OleAut32.dll", "long", "VariantClear", "ptr", $pvarg)
  121. If @error Then Return SetError(1, 0, 1)
  122. Return $aCall[0]
  123. EndFunc
  124. ; #FUNCTION# ====================================================================================================================
  125. ; Name...........: VariantCopy
  126. ; Description ...: Copies a VARIANT to another
  127. ; Syntax.........: VariantCopy($pvargDest, $pvargSrc)
  128. ; Parameters ....: $pvargDest - Destionation variant
  129. ; $pvargSrc - Source variant
  130. ; Return values .: Success - 0
  131. ; Failure - nonzero
  132. ; Author ........: Prog@ndy
  133. ; Modified.......:
  134. ; Remarks .......:
  135. ; Related .......: VariantRead
  136. ; Link ..........: http://msdn.microsoft.com/en-us/library/ms221697.aspx
  137. ; Example .......:
  138. ; ===============================================================================================================================
  139. Func VariantCopy($pvargDest, $pvargSrc)
  140. ; Author: Prog@ndy
  141. Local $aCall = DllCall("OleAut32.dll", "long", "VariantCopy", "ptr", $pvargDest, 'ptr', $pvargSrc)
  142. If @error Then Return SetError(1, 0, 1)
  143. Return $aCall[0]
  144. EndFunc
  145. ; #FUNCTION# ====================================================================================================================
  146. ; Name...........: VariantInit
  147. ; Description ...: Initializes a variant.
  148. ; Syntax.........: VariantInit($pvarg)
  149. ; Parameters ....: $pvarg - the VARIANT to initialize
  150. ; Return values .: Success - 0
  151. ; Failure - nonzero
  152. ; Author ........: Prog@ndy
  153. ; Modified.......:
  154. ; Remarks .......:
  155. ; Related .......: VariantClear
  156. ; Link ..........: http://msdn.microsoft.com/en-us/library/ms221402.aspx
  157. ; Example .......:
  158. ; ===============================================================================================================================
  159. Func VariantInit($pvarg)
  160. ; Author: Prog@ndy
  161. Local $aCall = DllCall("OleAut32.dll", "long", "VariantInit", "ptr", $pvarg)
  162. If @error Then Return SetError(1, 0, 1)
  163. Return $aCall[0]
  164. EndFunc
  165. ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  166. Func VariantChangeType( $pVarDest, $pVarSrc, $wFlags, $vt )
  167. Local $aRet = DllCall( "OleAut32.dll", "long", "VariantChangeType", "ptr", $pVarDest, "ptr", $pVarSrc, "word", $wFlags, "word", $vt )
  168. If @error Then Return SetError(1,0,1)
  169. Return $aRet[0]
  170. EndFunc
  171. Func VariantChangeTypeEx( $pVarDest, $pVarSrc, $lcid, $wFlags, $vt )
  172. Local $aRet = DllCall( "OleAut32.dll", "long", "VariantChangeTypeEx", "ptr", $pVarDest, "ptr", $pVarSrc, "word", $lcid, "word", $wFlags, "word", $vt )
  173. If @error Then Return SetError(1,0,1)
  174. Return $aRet[0]
  175. EndFunc
  176. Func VarAdd( $pVarLeft, $pVarRight, $pVarResult )
  177. Local $aRet = DllCall( "OleAut32.dll", "long", "VarAdd", "ptr", $pVarLeft, "ptr", $pVarRight, "ptr", $pVarResult )
  178. If @error Then Return SetError(1,0,1)
  179. Return $aRet[0]
  180. EndFunc
  181. Func VarSub( $pVarLeft, $pVarRight, $pVarResult )
  182. Local $aRet = DllCall( "OleAut32.dll", "long", "VarSub", "ptr", $pVarLeft, "ptr", $pVarRight, "ptr", $pVarResult )
  183. If @error Then Return SetError(1,0,1)
  184. Return $aRet[0]
  185. EndFunc
  186. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  187. ; BSTR (basic string) functions
  188. ; Copied from AutoItObject.au3 by the AutoItObject-Team: monoceres, trancexx, Kip, ProgAndy
  189. ; https://www.autoitscript.com/forum/index.php?showtopic=110379
  190. Func SysAllocString( $str )
  191. Local $aRet = DllCall( "OleAut32.dll", "ptr", "SysAllocString", "wstr", $str )
  192. If @error Then Return SetError(1, 0, 0)
  193. Return $aRet[0]
  194. EndFunc
  195. Func SysFreeString( $pBSTR )
  196. If Not $pBSTR Then Return SetError(1, 0, 0)
  197. DllCall( "OleAut32.dll", "none", "SysFreeString", "ptr", $pBSTR )
  198. If @error Then Return SetError(2, 0, 0)
  199. EndFunc
  200. Func SysReadString( $pBSTR, $iLen = -1 )
  201. If Not $pBSTR Then Return SetError(1, 0, "")
  202. If $iLen < 1 Then $iLen = SysStringLen( $pBSTR )
  203. If $iLen < 1 Then Return SetError(2, 0, "")
  204. Return DllStructGetData( DllStructCreate( "wchar[" & $iLen & "]", $pBSTR ), 1 )
  205. EndFunc
  206. Func SysStringLen( $pBSTR )
  207. If Not $pBSTR Then Return SetError(1, 0, 0)
  208. Local $aRet = DllCall( "OleAut32.dll", "uint", "SysStringLen", "ptr", $pBSTR )
  209. If @error Then Return SetError(2, 0, 0)
  210. Return $aRet[0]
  211. EndFunc
  212. ; ####################################################################################################
  213. ; ### ###
  214. ; ### SafeArray.au3 ###
  215. ; ### ###
  216. ; ####################################################################################################
  217. ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  218. Global Const $tagSAFEARRAYBOUND = _
  219. "ulong cElements;" & _ ; The number of elements in the dimension.
  220. "long lLbound;" ; The lower bound of the dimension.
  221. Global Const $tagSAFEARRAY = _
  222. "ushort cDims;" & _ ; The number of dimensions.
  223. "ushort fFeatures;" & _ ; Flags, see below.
  224. "ulong cbElements;" & _ ; The size of an array element.
  225. "ulong cLocks;" & _ ; The number of times the array has been locked without a corresponding unlock.
  226. "ptr pvData;" & _ ; The data.
  227. $tagSAFEARRAYBOUND ; One $tagSAFEARRAYBOUND for each dimension.
  228. ; fFeatures flags
  229. Global Const $FADF_AUTO = 0x0001 ; An array that is allocated on the stack.
  230. Global Const $FADF_STATIC = 0x0002 ; An array that is statically allocated.
  231. Global Const $FADF_EMBEDDED = 0x0004 ; An array that is embedded in a structure.
  232. Global Const $FADF_FIXEDSIZE = 0x0010 ; An array that may not be resized or reallocated.
  233. Global Const $FADF_RECORD = 0x0020 ; An array that contains records. When set, there will be a pointer to the IRecordInfo interface at negative offset 4 in the array descriptor.
  234. Global Const $FADF_HAVEIID = 0x0040 ; An array that has an IID identifying interface. When set, there will be a GUID at negative offset 16 in the safearray descriptor. Flag is set only when FADF_DISPATCH or FADF_UNKNOWN is also set.
  235. Global Const $FADF_HAVEVARTYPE = 0x0080 ; An array that has a variant type. The variant type can be retrieved with SafeArrayGetVartype.
  236. Global Const $FADF_BSTR = 0x0100 ; An array of BSTRs.
  237. Global Const $FADF_UNKNOWN = 0x0200 ; An array of IUnknown*.
  238. Global Const $FADF_DISPATCH = 0x0400 ; An array of IDispatch*.
  239. Global Const $FADF_VARIANT = 0x0800 ; An array of VARIANTs.
  240. Global Const $FADF_RESERVED = 0xF008 ; Bits reserved for future use.
  241. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  242. ; Safearray functions
  243. ; Copied from AutoItObject.au3 by the AutoItObject-Team: monoceres, trancexx, Kip, ProgAndy
  244. ; https://www.autoitscript.com/forum/index.php?showtopic=110379
  245. Func SafeArrayCreate($vType, $cDims, $rgsabound)
  246. ; Author: Prog@ndy
  247. Local $aCall = DllCall("OleAut32.dll", "ptr", "SafeArrayCreate", "dword", $vType, "uint", $cDims, 'struct*', $rgsabound)
  248. If @error Then Return SetError(1, 0, 0)
  249. Return $aCall[0]
  250. EndFunc
  251. Func SafeArrayDestroy($pSafeArray)
  252. ; Author: Prog@ndy
  253. Local $aCall = DllCall("OleAut32.dll", "int", "SafeArrayDestroy", "ptr", $pSafeArray)
  254. If @error Then Return SetError(1, 0, 1)
  255. Return $aCall[0]
  256. EndFunc
  257. Func SafeArrayAccessData($pSafeArray, ByRef $pArrayData)
  258. ; Author: Prog@ndy
  259. Local $aCall = DllCall("OleAut32.dll", "int", "SafeArrayAccessData", "ptr", $pSafeArray, 'ptr*', 0)
  260. If @error Then Return SetError(1, 0, 1)
  261. $pArrayData = $aCall[2]
  262. Return $aCall[0]
  263. EndFunc
  264. Func SafeArrayUnaccessData($pSafeArray)
  265. ; Author: Prog@ndy
  266. Local $aCall = DllCall("OleAut32.dll", "int", "SafeArrayUnaccessData", "ptr", $pSafeArray)
  267. If @error Then Return SetError(1, 0, 1)
  268. Return $aCall[0]
  269. EndFunc
  270. Func SafeArrayGetUBound($pSafeArray, $iDim, ByRef $iBound)
  271. ; Author: Prog@ndy
  272. Local $aCall = DllCall("OleAut32.dll", "int", "SafeArrayGetUBound", "ptr", $pSafeArray, 'uint', $iDim, 'long*', 0)
  273. If @error Then Return SetError(1, 0, 1)
  274. $iBound = $aCall[3]
  275. Return $aCall[0]
  276. EndFunc
  277. Func SafeArrayGetLBound($pSafeArray, $iDim, ByRef $iBound)
  278. ; Author: Prog@ndy
  279. Local $aCall = DllCall("OleAut32.dll", "int", "SafeArrayGetLBound", "ptr", $pSafeArray, 'uint', $iDim, 'long*', 0)
  280. If @error Then Return SetError(1, 0, 1)
  281. $iBound = $aCall[3]
  282. Return $aCall[0]
  283. EndFunc
  284. Func SafeArrayGetDim($pSafeArray)
  285. Local $aResult = DllCall("OleAut32.dll", "uint", "SafeArrayGetDim", "ptr", $pSafeArray)
  286. If @error Then Return SetError(1, 0, 0)
  287. Return $aResult[0]
  288. EndFunc
  289. ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  290. Func SafeArrayCopy( $pSafeArrayIn, ByRef $pSafeArrayOut )
  291. Local $aRet = DllCall( "OleAut32.dll", "int", "SafeArrayCopy", "ptr", $pSafeArrayIn, "ptr*", 0 )
  292. If @error Then Return SetError(1,0,1)
  293. $pSafeArrayOut = $aRet[2]
  294. Return $aRet[0]
  295. EndFunc
  296. Func SafeArrayCreateEmpty( $vType )
  297. Local $tsaBound = DllStructCreate( $tagSAFEARRAYBOUND )
  298. DllStructSetData( $tsaBound, "cElements", 0 )
  299. DllStructSetData( $tsaBound, "lLbound", 0 )
  300. Return SafeArrayCreate( $vType, 0, $tsaBound )
  301. EndFunc
  302. Func SafeArrayDestroyData( $pSafeArray )
  303. Local $aRet = DllCall( "OleAut32.dll", "int", "SafeArrayDestroyData", "ptr", $pSafeArray )
  304. If @error Then Return SetError(1,0,1)
  305. Return $aRet[0]
  306. EndFunc
  307. Func SafeArrayGetVartype( $pSafeArray, ByRef $vt )
  308. Local $aRet = DllCall( "OleAut32.dll", "int", "SafeArrayGetVartype", "ptr", $pSafeArray, "ptr*", 0 )
  309. If @error Then Return SetError(1,0,1)
  310. $vt = $aRet[2]
  311. Return $aRet[0]
  312. EndFunc
  313. ; ####################################################################################################
  314. ; ### ###
  315. ; ### COMUtils.au3 ###
  316. ; ### ###
  317. ; ####################################################################################################
  318. Func CoCreateInstance( $rclsid, $pUnkOuter, $ClsContext, $riid, ByRef $ppv )
  319. Local $aRet = DllCall( "ole32.dll", "long", "CoCreateInstance", "struct*", $rclsid, "ptr", $pUnkOuter, "dword", $ClsContext, "struct*", $riid, "ptr*", 0 )
  320. If @error Then Return SetError(1,0,1)
  321. $ppv = $aRet[5]
  322. Return $aRet[0]
  323. EndFunc
  324. ; Add these lines to a script to activate the error handler:
  325. ;Local $oComErrFunc = ObjEvent( "AutoIt.Error", "ComErrFunc" )
  326. ;#forceref $oComErrFunc
  327. Func ComErrFunc( $oError )
  328. ConsoleWrite( @ScriptName & "(" & $oError.scriptline & "): ==> COM Error intercepted!" & @CRLF & _
  329. @TAB & "Err.number is: " & @TAB & @TAB & "0x" & Hex( $oError.number ) & @CRLF & _
  330. @TAB & "Err.windescription:" & @TAB & $oError.windescription & _
  331. @TAB & "Err.description is: " & @TAB & $oError.description & @CRLF & _
  332. @TAB & "Err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
  333. @TAB & "Err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
  334. @TAB & "Err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
  335. @TAB & "Err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
  336. @TAB & "Err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
  337. @TAB & "Err.retcode is: " & @TAB & "0x" & Hex( $oError.retcode ) & @CRLF )
  338. EndFunc
  339. ; Copied from "Hooking into the IDispatch interface" by monoceres
  340. ; https://www.autoitscript.com/forum/index.php?showtopic=107678
  341. Func ReplaceVTableFuncPtr( $pVTable, $iOffset, $pNewFunc )
  342. Local $pPointer = DllStructGetData( DllStructCreate( "ptr", $pVTable ), 1 ) + $iOffset, $PAGE_EXECUTE_READWRITE = 0x40
  343. Local $pOldFunc = DllStructGetData( DllStructCreate( "ptr", $pPointer ), 1 ) ; Get the original function pointer in VTable
  344. Local $aRet = DllCall( "Kernel32.dll", "int", "VirtualProtect", "ptr", $pPointer, "long", @AutoItX64 ? 8 : 4, "dword", $PAGE_EXECUTE_READWRITE, "dword*", 0 ) ; Unprotect memory
  345. DllStructSetData( DllStructCreate( "ptr", $pPointer ), 1, $pNewFunc ) ; Replace function pointer in VTable with $pNewFunc function pointer
  346. DllCall( "Kernel32.dll", "int", "VirtualProtect", "ptr", $pPointer, "long", @AutoItX64 ? 8 : 4, "dword", $aRet[4], "dword*", 0 ) ; Protect memory
  347. Return $pOldFunc ; Return original function pointer
  348. EndFunc
  349. ; ####################################################################################################
  350. ; ### ###
  351. ; ### AccessingVariables.au3 ###
  352. ; ### ###
  353. ; ####################################################################################################
  354. Global $oAccVars_Object = AccVars_Init(), $hAccVars_MethodFunc
  355. ; --- The first part of the UDF creates $oAccVars_Object and implements method functions ---
  356. Func AccVars_Init()
  357. ; Three locals copied from "IUIAutomation MS framework automate chrome, FF, IE, ...." by junkew
  358. ; https://www.autoitscript.com/forum/index.php?showtopic=153520
  359. Local $sCLSID_CUIAutomation = "{FF48DBA4-60EF-4201-AA87-54103EEF594E}"
  360. Local $sIID_IUIAutomation = "{30CBE57D-D9D0-452A-AB13-7AC5AC4825EE}"
  361. Local $stag_IUIAutomation = _
  362. "AccVars_VariableToVariant01 hresult(variant*);" & _
  363. "AccVars_VariableToVariant02 hresult(variant*;variant*);"
  364. ; Create AccVars object (Automation object)
  365. Local $oAccVars_Object = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $stag_IUIAutomation )
  366. If Not IsObj( $oAccVars_Object ) Then Return SetError(1,0,1)
  367. ; Replace original methods with AccVars_VariableToVariantXY methods
  368. Local $pVariableToVariant, $pAccessVariable = Ptr( $oAccVars_Object() ), $sFuncName, $sFuncParams = "ptr", $iOffset, $iPtrSize = @AutoItX64 ? 8 : 4
  369. For $i = 1 To 2
  370. $sFuncName = "AccVars_VariableToVariant" & StringFormat( "%02i", $i )
  371. $sFuncParams &= ";ptr*"
  372. $iOffset = ( 3 + $i - 1 ) * $iPtrSize
  373. $pVariableToVariant = DllCallbackGetPtr( DllCallbackRegister( $sFuncName, "long", $sFuncParams ) )
  374. ReplaceVTableFuncPtr( $pAccessVariable, $iOffset, $pVariableToVariant )
  375. Next
  376. Return $oAccVars_Object
  377. EndFunc
  378. Func AccVars_VariableToVariant01( $pSelf, $pVariant01 )
  379. $hAccVars_MethodFunc( $pVariant01 )
  380. Return 0 ; $S_OK (COM constant)
  381. #forceref $pSelf
  382. EndFunc
  383. Func AccVars_VariableToVariant02( $pSelf, $pVariant01, $pVariant02 )
  384. $hAccVars_MethodFunc( $pVariant01, $pVariant02 )
  385. Return 0 ; $S_OK (COM constant)
  386. #forceref $pSelf
  387. EndFunc
  388. ; --- The last part of the UDF creates a set of easy to use functions to call the object methods ---
  389. Func AccessVariables01( $hAccVars_Method, ByRef $vVariable01 )
  390. $hAccVars_MethodFunc = $hAccVars_Method
  391. $oAccVars_Object.AccVars_VariableToVariant01( $vVariable01 )
  392. EndFunc
  393. Func AccessVariables02( $hAccVars_Method, ByRef $vVariable01, ByRef $vVariable02 )
  394. $hAccVars_MethodFunc = $hAccVars_Method
  395. $oAccVars_Object.AccVars_VariableToVariant02( $vVariable01, $vVariable02 )
  396. EndFunc
  397. ; ####################################################################################################
  398. ; ### ###
  399. ; ### AccVarsUtilities.au3 ###
  400. ; ### ###
  401. ; ####################################################################################################
  402. ; --- AccVars_ArrayToSafeArray ---
  403. ; The AutoIt array and the safearray are arrays of variants
  404. Func AccVars_ArrayToSafeArray( ByRef $aArray, ByRef $pSafeArray )
  405. AccessVariables01( AccVars_ArrayToSafeArrayConvert, $aArray )
  406. AccVars_ArrayToSafeArrayData( $pSafeArray )
  407. EndFunc
  408. Func AccVars_ArrayToSafeArrayConvert( $pArray )
  409. ; <<<< On function entry the native AutoIt array is converted to a safearray contained in a variant >>>>
  410. ; Get safearray pointer
  411. Local $pSafeArrayFromArray = DllStructGetData( DllStructCreate( "ptr", $pArray + 8 ), 1 )
  412. Local $pSafeArray
  413. SafeArrayCopy( $pSafeArrayFromArray, $pSafeArray )
  414. If @error Then Return SetError(1,0,0)
  415. AccVars_ArrayToSafeArrayData( $pSafeArray, 1 )
  416. EndFunc
  417. Func AccVars_ArrayToSafeArrayData( ByRef $pSafeArray, $bSet = 0 )
  418. Static $pStaticSafeArray
  419. If $bSet Then
  420. $pStaticSafeArray = $pSafeArray
  421. Else
  422. $pSafeArray = $pStaticSafeArray
  423. EndIf
  424. EndFunc
  425. ; --- AccVars_SafeArrayToArray ---
  426. ; The safearray and the AutoIt array are arrays of variants
  427. Func AccVars_SafeArrayToArray( ByRef $pSafeArray, ByRef $aArray )
  428. AccessVariables02( AccVars_SafeArrayToArrayConvert, $pSafeArray, $aArray )
  429. EndFunc
  430. Func AccVars_SafeArrayToArrayConvert( $pvSafeArray, $pArray )
  431. ; --- Get safearray information ---
  432. ; $pvSafeArray is a variant that contains a pointer
  433. Local $pSafeArray = DllStructGetData( DllStructCreate( "ptr", $pvSafeArray + 8 ), 1 )
  434. ; Array type
  435. Local $iVarType
  436. SafeArrayGetVartype( $pSafeArray, $iVarType )
  437. Switch $iVarType
  438. Case $VT_I2, $VT_I4 ; Signed integers
  439. Case $VT_R4, $VT_R8 ; 4/8 bytes floats
  440. Case $VT_BSTR ; Basic string
  441. Case $VT_BOOL ; Boolean type
  442. Case $VT_UI4, $VT_UI8 ; 4/8 bytes unsigned integers
  443. Case $VT_VARIANT ; Variant data type
  444. Case $VT_UNKNOWN ; IUnknown pointer
  445. ; $pSafeArray is not compatible with a native AutoIt array
  446. ; Convert $pSafeArray to a compatible safearray in $pSafeArray2
  447. Local $tSafeArray = DllStructCreate( $tagSAFEARRAY, $pSafeArray )
  448. Local $tSafeArrayBound = DllStructCreate( $tagSAFEARRAYBOUND )
  449. Local $iElements = DllStructGetData( $tSafeArray, "cElements" )
  450. DllStructSetData( $tSafeArrayBound, "cElements", $iElements )
  451. DllStructSetData( $tSafeArrayBound, "lLbound", DllStructGetData( $tSafeArray, "lLbound" ) )
  452. Local $pSafeArray2 = SafeArrayCreate( $VT_VARIANT, 1, $tSafeArrayBound ), $pArrayData, $pArrayData2
  453. SafeArrayAccessData( $pSafeArray2, $pArrayData2 )
  454. SafeArrayAccessData( $pSafeArray, $pArrayData )
  455. $iVarType = @AutoItX64 ? $VT_UI8 : $VT_UI4
  456. Local $iVarSize = @AutoItX64 ? 24 : 16
  457. Local $iPtrSize = @AutoItX64 ? 8 : 4
  458. For $i = 0 To $iElements - 1 ; Set variant type and data
  459. DllStructSetData( DllStructCreate( "word", $pArrayData2 + $i * $iVarSize ), 1, $iVarType )
  460. DllStructSetData( DllStructCreate( "uint_ptr", 8 + $pArrayData2 + $i * $iVarSize ), 1, DllStructGetData( DllStructCreate( "ptr", $pArrayData + $i * $iPtrSize ), 1 ) )
  461. Next
  462. SafeArrayUnaccessData( $pSafeArray )
  463. SafeArrayUnaccessData( $pSafeArray2 )
  464. SafeArrayCopy( $pSafeArray2, $pSafeArray )
  465. SafeArrayDestroy( $pSafeArray2 )
  466. Case Else
  467. Return SetError(1,0,0)
  468. EndSwitch
  469. ; --- Set $pArray to match an array ---
  470. ; Set vt element to $VT_ARRAY + $iVarType
  471. DllStructSetData( DllStructCreate( "word", $pArray ), 1, $VT_ARRAY + $iVarType )
  472. ; Set data element to safearray pointer
  473. DllStructSetData( DllStructCreate( "ptr", $pArray + 8 ), 1, $pSafeArray )
  474. ; <<<< On function exit the safearray contained in a variant is converted to a native AutoIt array >>>>
  475. EndFunc
  476. ; --- AccVars_ArrayToSafeArrayOfVartype ---
  477. ; The returned safearray is an array of the specified variant type
  478. Func AccVars_ArrayToSafeArrayOfVartype( ByRef $aArray, $iVartype )
  479. Local $tsaBound = DllStructCreate( $tagSAFEARRAYBOUND ), $pSafeArray, $pSafeArrayData, $iArray = UBound( $aArray ), $iPtrSize = @AutoItX64 ? 8 : 4
  480. DllStructSetData( $tsaBound, "cElements", $iArray )
  481. DllStructSetData( $tsaBound, "lLbound", 0 )
  482. $pSafeArray = SafeArrayCreate( $iVartype, 1, $tsaBound )
  483. SafeArrayAccessData( $pSafeArray, $pSafeArrayData )
  484. For $i = 0 To $iArray - 1
  485. DllStructSetData( DllStructCreate( "ptr", $pSafeArrayData + $iPtrSize * $i ), 1, SysAllocString( $aArray[$i] ) )
  486. Next
  487. SafeArrayUnaccessData( $pSafeArray )
  488. Return $pSafeArray
  489. EndFunc
  490. ; --- AccVars_SafeArrayToSafeArrayOfVariant ---
  491. ; Returns a safearray with one variant element
  492. ; The variant element contains the input safearray
  493. Func AccVars_SafeArrayToSafeArrayOfVariant( ByRef $pSafeArrayIn )
  494. Local $iVartype, $tsaBound = DllStructCreate( $tagSAFEARRAYBOUND ), $pSafeArrayOut, $pSafeArrayOutData
  495. SafeArrayGetVartype( $pSafeArrayIn, $iVartype )
  496. DllStructSetData( $tsaBound, "cElements", 1 )
  497. DllStructSetData( $tsaBound, "lLbound", 0 )
  498. $pSafeArrayOut = SafeArrayCreate( $VT_VARIANT, 1, $tsaBound )
  499. SafeArrayAccessData( $pSafeArrayOut, $pSafeArrayOutData )
  500. DllStructSetData( DllStructCreate( "word", $pSafeArrayOutData ), 1, $iVartype + $VT_ARRAY )
  501. DllStructSetData( DllStructCreate( "ptr", $pSafeArrayOutData + 8 ), 1, $pSafeArrayIn )
  502. SafeArrayUnaccessData( $pSafeArrayOut )
  503. Return $pSafeArrayOut
  504. EndFunc
  505. ; --- AccVars_VariantToVariable ---
  506. Func AccVars_VariantToVariable( ByRef $pVariant )
  507. Switch DllStructGetData( DllStructCreate( "word", $pVariant ), 1 )
  508. Case $VT_I4, $VT_I8 ; 4/8 bytes signed integer
  509. Return DllStructGetData( DllStructCreate( "int", $pVariant + 8 ), 1 )
  510. Case $VT_R8 ; 8 bytes double
  511. Return DllStructGetData( DllStructCreate( "double", $pVariant + 8 ), 1 )
  512. Case $VT_BSTR ; Basic string
  513. Return SysReadString( DllStructGetData( DllStructCreate( "ptr", $pVariant + 8 ), 1 ) )
  514. Case $VT_BOOL ; 2 bytes boolean
  515. Return DllStructGetData( DllStructCreate( "short", $pVariant + 8 ), 1 )
  516. Case $VT_UI4, $VT_UI8 ; 4/8 bytes unsigned integer
  517. Return DllStructGetData( DllStructCreate( "ptr", $pVariant + 8 ), 1 )
  518. Case Else
  519. Return SetError(1,0,0)
  520. EndSwitch
  521. EndFunc
  522. ; --- AccVars_VariableToVariant ---
  523. Func AccVars_VariableToVariant( $vVariable, ByRef $pVariant )
  524. Switch VarGetType( $vVariable )
  525. Case "Bool"
  526. DllStructSetData( DllStructCreate( "word", $pVariant ), 1, $VT_BOOL )
  527. DllStructSetData( DllStructCreate( "short", $pVariant + 8 ), 1, $vVariable )
  528. Case "Double"
  529. DllStructSetData( DllStructCreate( "word", $pVariant ), 1, $VT_R8 )
  530. DllStructSetData( DllStructCreate( "double", $pVariant + 8 ), 1, $vVariable )
  531. Case "Int32"
  532. DllStructSetData( DllStructCreate( "word", $pVariant ), 1, $VT_I4 )
  533. DllStructSetData( DllStructCreate( "int", $pVariant + 8 ), 1, $vVariable )
  534. Case "Ptr"
  535. DllStructSetData( DllStructCreate( "word", $pVariant ), 1, @AutoItX64 ? $VT_UI8 : $VT_UI4 )
  536. DllStructSetData( DllStructCreate( "ptr", $pVariant + 8 ), 1, $vVariable )
  537. Case "String"
  538. DllStructSetData( DllStructCreate( "word", $pVariant ), 1, $VT_BSTR )
  539. DllStructSetData( DllStructCreate( "ptr", $pVariant + 8 ), 1, SysAllocString( $vVariable ) )
  540. Case Else
  541. Return SetError(1,0,0)
  542. EndSwitch
  543. EndFunc
  544. ; ####################################################################################################
  545. ; ### ###
  546. ; ### Interfaces.au3 ###
  547. ; ### ###
  548. ; ####################################################################################################
  549. Global Const $sCLSID_CorRuntimeHost = "{CB2F6723-AB3A-11D2-9C40-00C04FA30A3E}"
  550. Global Const $tCLSID_CorRuntimeHost = CLSIDFromString( $sCLSID_CorRuntimeHost )
  551. Global Const $sIID_ICorRuntimeHost = "{CB2F6722-AB3A-11D2-9C40-00C04FA30A3E}"
  552. Global Const $tIID_ICorRuntimeHost = CLSIDFromString( $sIID_ICorRuntimeHost )
  553. Global Const $sTag_ICorRuntimeHost = _
  554. "CreateLogicalThreadState hresult();" & _
  555. "DeleteLogicalThreadState hresult();" & _
  556. "SwitchInLogicalThreadState hresult();" & _
  557. "SwitchOutLogicalThreadState hresult();" & _
  558. "LocksHeldByLogicalThread hresult();" & _
  559. "MapFile hresult();" & _
  560. "GetConfiguration hresult();" & _
  561. "Start hresult();" & _
  562. "Stop hresult();" & _
  563. "CreateDomain hresult();" & _
  564. "GetDefaultDomain hresult(ptr*);" & _
  565. "EnumDomains hresult(ptr*);" & _
  566. "NextDomain hresult(ptr;ptr*);" & _
  567. "CloseEnum hresult();" & _
  568. "CreateDomainEx hresult();" & _
  569. "CreateDomainSetup hresult();" & _
  570. "CreateEvidence hresult();" & _
  571. "UnloadDomain hresult(ptr);" & _
  572. "CurrentDomain hresult();"
  573. Global Const $sIID_IDispatch = "{00020400-0000-0000-C000-000000000046}"
  574. Global Const $sTag_IDispatch = _
  575. "GetTypeInfoCount hresult(dword*);" & _
  576. "GetTypeInfo hresult(dword;dword;ptr*);" & _
  577. "GetIDsOfNames hresult(ptr;ptr;dword;dword;ptr);" & _
  578. "Invoke hresult(dword;ptr;dword;word;ptr;ptr;ptr;ptr);"
  579. ; The interfaces _AppDomain, _Type and _Assembly below that starts with
  580. ; an underscore are the interfaces that can be used from unmanaged code.
  581. Global Const $sIID__AppDomain = "{05F696DC-2B29-3663-AD8B-C4389CF2A713}"
  582. Global Const $sTag__AppDomain = _
  583. $sTag_IDispatch & _
  584. "get_ToString hresult();" & _
  585. "Equals hresult();" & _
  586. "GetHashCode hresult();" & _
  587. "GetType hresult(ptr*);" & _
  588. "InitializeLifetimeService hresult();" & _
  589. "GetLifetimeService hresult();" & _
  590. "get_Evidence hresult();" & _
  591. "add_DomainUnload hresult();" & _
  592. "remove_DomainUnload hresult();" & _
  593. "add_AssemblyLoad hresult();" & _
  594. "remove_AssemblyLoad hresult();" & _
  595. "add_ProcessExit hresult();" & _
  596. "remove_ProcessExit hresult();" & _
  597. "add_TypeResolve hresult();" & _
  598. "remove_TypeResolve hresult();" & _
  599. "add_ResourceResolve hresult();" & _
  600. "remove_ResourceResolve hresult();" & _
  601. "add_AssemblyResolve hresult();" & _
  602. "remove_AssemblyResolve hresult();" & _
  603. "add_UnhandledException hresult();" & _
  604. "remove_UnhandledException hresult();" & _
  605. "DefineDynamicAssembly hresult();" & _
  606. "DefineDynamicAssembly_2 hresult();" & _
  607. "DefineDynamicAssembly_3 hresult();" & _
  608. "DefineDynamicAssembly_4 hresult();" & _
  609. "DefineDynamicAssembly_5 hresult();" & _
  610. "DefineDynamicAssembly_6 hresult();" & _
  611. "DefineDynamicAssembly_7 hresult();" & _
  612. "DefineDynamicAssembly_8 hresult();" & _
  613. "DefineDynamicAssembly_9 hresult();" & _
  614. "CreateInstance hresult(bstr;bstr;object*);" & _
  615. "CreateInstanceFrom hresult();" & _
  616. "CreateInstance_2 hresult();" & _
  617. "CreateInstanceFrom_2 hresult();" & _
  618. "CreateInstance_3 hresult(bstr;bstr;bool;int;ptr;ptr;ptr;ptr;ptr;ptr*);" & _
  619. "CreateInstanceFrom_3 hresult();" & _
  620. "Load hresult();" & _
  621. "Load_2 hresult();" & _
  622. "Load_3 hresult();" & _
  623. "Load_4 hresult();" & _
  624. "Load_5 hresult();" & _
  625. "Load_6 hresult();" & _
  626. "Load_7 hresult();" & _
  627. "ExecuteAssembly hresult();" & _
  628. "ExecuteAssembly_2 hresult();" & _
  629. "ExecuteAssembly_3 hresult();" & _
  630. "get_FriendlyName hresult(bstr*);" & _
  631. "get_BaseDirectory hresult(bstr*);" & _
  632. "get_RelativeSearchPath hresult();" & _
  633. "get_ShadowCopyFiles hresult();" & _
  634. "GetAssemblies hresult(ptr*);" & _
  635. "AppendPrivatePath hresult();" & _
  636. "ClearPrivatePath ) = 0; hresult();" & _
  637. "SetShadowCopyPath hresult();" & _
  638. "ClearShadowCopyPath ) = 0; hresult();" & _
  639. "SetCachePath hresult();" & _
  640. "SetData hresult();" & _
  641. "GetData hresult();" & _
  642. "SetAppDomainPolicy hresult();" & _
  643. "SetThreadPrincipal hresult();" & _
  644. "SetPrincipalPolicy hresult();" & _
  645. "DoCallBack hresult();" & _
  646. "get_DynamicDirectory hresult();"
  647. Global Const $sIID__Type = "{BCA8B44D-AAD6-3A86-8AB7-03349F4F2DA2}"
  648. Global Const $sTag__Type = _
  649. $sTag_IDispatch & _
  650. "get_ToString hresult(bstr*);" & _
  651. "Equals hresult(variant;short*);" & _
  652. "GetHashCode hresult(int*);" & _
  653. "GetType hresult(ptr);" & _
  654. "get_MemberType hresult(ptr);" & _
  655. "get_name hresult(bstr*);" & _
  656. "get_DeclaringType hresult(ptr);" & _
  657. "get_ReflectedType hresult(ptr);" & _
  658. "GetCustomAttributes hresult(ptr;short;ptr);" & _
  659. "GetCustomAttributes_2 hresult(short;ptr);" & _
  660. "IsDefined hresult(ptr;short;short*);" & _
  661. "get_Guid hresult(ptr);" & _
  662. "get_Module hresult(ptr);" & _
  663. "get_Assembly hresult(ptr*);" & _
  664. "get_TypeHandle hresult(ptr);" & _
  665. "get_FullName hresult(bstr*);" & _
  666. "get_Namespace hresult(bstr*);" & _
  667. "get_AssemblyQualifiedName hresult(bstr*);" & _
  668. "GetArrayRank hresult(int*);" & _
  669. "get_BaseType hresult(ptr);" & _
  670. "GetConstructors hresult(ptr;ptr);" & _
  671. "GetInterface hresult(bstr;short;ptr);" & _
  672. "GetInterfaces hresult(ptr);" & _
  673. "FindInterfaces hresult(ptr;variant;ptr);" & _
  674. "GetEvent hresult(bstr;ptr;ptr);" & _
  675. "GetEvents hresult(ptr);" & _
  676. "GetEvents_2 hresult(int;ptr);" & _
  677. "GetNestedTypes hresult(int;ptr);" & _
  678. "GetNestedType hresult(bstr;ptr;ptr);" & _
  679. "GetMember hresult(bstr;ptr;ptr;ptr);" & _
  680. "GetDefaultMembers hresult(ptr);" & _
  681. "FindMembers hresult(ptr;ptr;ptr;variant;ptr);" & _
  682. "GetElementType hresult(ptr);" & _
  683. "IsSubclassOf hresult(ptr;short*);" & _
  684. "IsInstanceOfType hresult(variant;short*);" & _
  685. "IsAssignableFrom hresult(ptr;short*);" & _
  686. "GetInterfaceMap hresult(ptr;ptr);" & _
  687. "GetMethod hresult(bstr;ptr;ptr;ptr;ptr;ptr);" & _
  688. "GetMethod_2 hresult(bstr;ptr;ptr);" & _
  689. "GetMethods hresult(int;ptr);" & _
  690. "GetField hresult(bstr;ptr;ptr);" & _
  691. "GetFields hresult(int;ptr);" & _
  692. "GetProperty hresult(bstr;ptr;ptr);" & _
  693. "GetProperty_2 hresult(bstr;ptr;ptr;ptr;ptr;ptr;ptr);" & _
  694. "GetProperties hresult(ptr;ptr);" & _
  695. "GetMember_2 hresult(bstr;ptr;ptr);" & _
  696. "GetMembers hresult(int;ptr*);" & _
  697. "InvokeMember hresult(bstr;ptr;ptr;variant;ptr;ptr;ptr;ptr;variant*);" & _
  698. "get_UnderlyingSystemType hresult(ptr);" & _
  699. "InvokeMember_2 hresult(bstr;int;ptr;variant;ptr;ptr;variant*);" & _
  700. "InvokeMember_3 hresult(bstr;int;ptr;variant;ptr;variant*);" & _
  701. "GetConstructor hresult(ptr;ptr;ptr;ptr;ptr;ptr);" & _
  702. "GetConstructor_2 hresult(ptr;ptr;ptr;ptr;ptr);" & _
  703. "GetConstructor_3 hresult(ptr;ptr);" & _
  704. "GetConstructors_2 hresult(ptr);" & _
  705. "get_TypeInitializer hresult(ptr);" & _
  706. "GetMethod_3 hresult(bstr;ptr;ptr;ptr;ptr;ptr;ptr);" & _
  707. "GetMethod_4 hresult(bstr;ptr;ptr;ptr);" & _
  708. "GetMethod_5 hresult(bstr;ptr;ptr);" & _
  709. "GetMethod_6 hresult(bstr;ptr);" & _
  710. "GetMethods_2 hresult(ptr);" & _
  711. "GetField_2 hresult(bstr;ptr);" & _
  712. "GetFields_2 hresult(ptr);" & _
  713. "GetInterface_2 hresult(bstr;ptr);" & _
  714. "GetEvent_2 hresult(bstr;ptr);" & _
  715. "GetProperty_3 hresult(bstr;ptr;ptr;ptr;ptr);" & _
  716. "GetProperty_4 hresult(bstr;ptr;ptr;ptr);" & _
  717. "GetProperty_5 hresult(bstr;ptr;ptr);" & _
  718. "GetProperty_6 hresult(bstr;ptr;ptr);" & _
  719. "GetProperty_7 hresult(bstr;ptr);" & _
  720. "GetProperties_2 hresult(ptr);" & _
  721. "GetNestedTypes_2 hresult(ptr);" & _
  722. "GetNestedType_2 hresult(bstr;ptr);" & _
  723. "GetMember_3 hresult(bstr;ptr);" & _
  724. "GetMembers_2 hresult(ptr);" & _
  725. "get_Attributes hresult(ptr);" & _
  726. "get_IsNotPublic hresult(short*);" & _
  727. "get_IsPublic hresult(short*);" & _
  728. "get_IsNestedPublic hresult(short*);" & _
  729. "get_IsNestedPrivate hresult(short*);" & _
  730. "get_IsNestedFamily hresult(short*);" & _
  731. "get_IsNestedAssembly hresult(short*);" & _
  732. "get_IsNestedFamANDAssem hresult(short*);" & _
  733. "get_IsNestedFamORAssem hresult(short*);" & _
  734. "get_IsAutoLayout hresult(short*);" & _
  735. "get_IsLayoutSequential hresult(short*);" & _
  736. "get_IsExplicitLayout hresult(short*);" & _
  737. "get_IsClass hresult(short*);" & _
  738. "get_IsInterface hresult(short*);" & _
  739. "get_IsValueType hresult(short*);" & _
  740. "get_IsAbstract hresult(short*);" & _
  741. "get_IsSealed hresult(short*);" & _
  742. "get_IsEnum hresult(short*);" & _
  743. "get_IsSpecialName hresult(short*);" & _
  744. "get_IsImport hresult(short*);" & _
  745. "get_IsSerializable hresult(short*);" & _
  746. "get_IsAnsiClass hresult(short*);" & _
  747. "get_IsUnicodeClass hresult(short*);" & _
  748. "get_IsAutoClass hresult(short*);" & _
  749. "get_IsArray hresult(short*);" & _
  750. "get_IsByRef hresult(short*);" & _
  751. "get_IsPointer hresult(short*);" & _
  752. "get_IsPrimitive hresult(short*);" & _
  753. "get_IsCOMObject hresult(short*);" & _
  754. "get_HasElementType hresult(short*);" & _
  755. "get_IsContextful hresult(short*);" & _
  756. "get_IsMarshalByRef hresult(short*);" & _
  757. "Equals_2 hresult(ptr;short*);"
  758. ; Binding flags for InvokeMember, InvokeMember_2
  759. ; and InvokeMember_3 methods of _Type interface.
  760. Global Const $BindingFlags_Default = 0x0000
  761. Global Const $BindingFlags_IgnoreCase = 0x0001
  762. Global Const $BindingFlags_DeclaredOnly = 0x0002
  763. Global Const $BindingFlags_Instance = 0x0004
  764. Global Const $BindingFlags_Static = 0x0008
  765. Global Const $BindingFlags_Public = 0x0010
  766. Global Const $BindingFlags_NonPublic = 0x0020
  767. Global Const $BindingFlags_FlattenHierarchy = 0x0040
  768. Global Const $BindingFlags_InvokeMethod = 0x0100
  769. Global Const $BindingFlags_CreateInstance = 0x0200
  770. Global Const $BindingFlags_GetField = 0x0400
  771. Global Const $BindingFlags_SetField = 0x0800
  772. Global Const $BindingFlags_GetProperty = 0x1000
  773. Global Const $BindingFlags_SetProperty = 0x2000
  774. Global Const $BindingFlags_PutDispProperty = 0x4000
  775. Global Const $BindingFlags_PutRefDispProperty = 0x8000
  776. Global Const $BindingFlags_ExactBinding = 0x00010000
  777. Global Const $BindingFlags_SuppressChangeType = 0x00020000
  778. Global Const $BindingFlags_OptionalParamBinding = 0x00040000
  779. Global Const $BindingFlags_IgnoreReturn = 0x01000000
  780. Global Const $BindingFlags_DefaultValue = $BindingFlags_Static + $BindingFlags_Public + $BindingFlags_FlattenHierarchy + $BindingFlags_InvokeMethod
  781. Global Const $sIID__Assembly = "{17156360-2F1A-384A-BC52-FDE93C215C5B}"
  782. Global Const $sTag__Assembly = _
  783. $sTag_IDispatch & _
  784. "get_ToString hresult(bstr*);" & _
  785. "Equals hresult();" & _
  786. "GetHashCode hresult();" & _
  787. "GetType hresult(ptr*);" & _
  788. "get_CodeBase hresult();" & _
  789. "get_EscapedCodeBase hresult();" & _
  790. "GetName hresult();" & _
  791. "GetName_2 hresult();" & _
  792. "get_FullName hresult(bstr*);" & _
  793. "get_EntryPoint hresult();" & _
  794. "GetType_2 hresult(bstr;ptr*);" & _
  795. "GetType_3 hresult();" & _
  796. "GetExportedTypes hresult();" & _
  797. "GetTypes hresult(ptr*);" & _
  798. "GetManifestResourceStream hresult();" & _
  799. "GetManifestResourceStream_2 hresult();" & _
  800. "GetFile hresult();" & _
  801. "GetFiles hresult();" & _
  802. "GetFiles_2 hresult();" & _
  803. "GetManifestResourceNames hresult();" & _
  804. "GetManifestResourceInfo hresult();" & _
  805. "get_Location hresult(bstr*);" & _
  806. "get_Evidence hresult();" & _
  807. "GetCustomAttributes hresult();" & _
  808. "GetCustomAttributes_2 hresult();" & _
  809. "IsDefined hresult();" & _
  810. "GetObjectData hresult();" & _
  811. "add_ModuleResolve hresult();" & _
  812. "remove_ModuleResolve hresult();" & _
  813. "GetType_4 hresult();" & _
  814. "GetSatelliteAssembly hresult();" & _
  815. "GetSatelliteAssembly_2 hresult();" & _
  816. "LoadModule hresult();" & _
  817. "LoadModule_2 hresult();" & _
  818. "CreateInstance hresult(bstr;variant*);" & _
  819. "CreateInstance_2 hresult(bstr;bool;variant*);" & _
  820. "CreateInstance_3 hresult(bstr;bool;int;ptr;ptr;ptr;ptr;variant*);" & _
  821. "GetLoadedModules hresult();" & _
  822. "GetLoadedModules_2 hresult();" & _
  823. "GetModules hresult();" & _
  824. "GetModules_2 hresult();" & _
  825. "GetModule hresult();" & _
  826. "GetReferencedAssemblies hresult();" & _
  827. "get_GlobalAssemblyCache hresult(bool*);"
  828. Func CLSIDFromString( $sGUID )
  829. Static $hOle32Dll = "ole32.dll", $tGUID = DllStructCreate( "ulong Data1;ushort Data2;ushort Data3;byte Data4[8]" ), $pGUID = DllStructGetPtr( $tGUID )
  830. DllCall( $hOle32Dll, "uint", "CLSIDFromString", "wstr", $sGUID, "ptr", $pGUID )
  831. Return $tGUID
  832. EndFunc
  833. Func GUIDFromStringEx( $sGUID, $tGUID )
  834. Static $hOle32Dll = "ole32.dll"
  835. DllCall( $hOle32Dll, "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID )
  836. EndFunc
  837. ; ####################################################################################################
  838. ; ### ###
  839. ; ### DotNet.au3 ###
  840. ; ### ###
  841. ; ####################################################################################################
  842. Func DotNet_Start( $sVersion = "" )
  843. Static $pRuntimeHost = 0, $oRuntimeHost
  844. If $pRuntimeHost Then Return $oRuntimeHost
  845. If $sVersion = "" Then
  846. Local $sPath = @WindowsDir & "\Microsoft.NET\Framework" & ( @AutoItX64 ? "64" : "" ) & "\"
  847. Local $hSearch = FileFindFirstFile( $sPath & "v?.*" ), $sFolder
  848. If $hSearch <> -1 Then
  849. While 1
  850. $sFolder = FileFindNextFile( $hSearch )
  851. Local $iError = @error, $iExtended = @extended
  852. If $iExtended = 1 And FileExists( $sPath & $sFolder & "\mscorlib.dll" ) And $sVersion < $sFolder Then $sVersion = $sFolder
  853. If $iError Then ExitLoop
  854. WEnd
  855. EndIf
  856. ElseIf Not FileExists( @WindowsDir & "\Microsoft.NET\Framework" & ( @AutoItX64 ? "64" : "" ) & "\" & $sVersion ) Then
  857. Return SetError( 1,0,0 )
  858. EndIf
  859. Local Const $tagGUID = "struct; ulong Data1;ushort Data2;ushort Data3;byte Data4[8]; endstruct"
  860. Local $tCLSID_CorRuntimeHost = DllStructCreate( $tagGUID )
  861. GUIDFromStringEx( $sCLSID_CorRuntimeHost, $tCLSID_CorRuntimeHost )
  862. Local $tIID_ICorRuntimeHost = DllStructCreate( $tagGUID )
  863. GUIDFromStringEx( $sIID_ICorRuntimeHost, $tIID_ICorRuntimeHost )
  864. Local $aRet = DllCall( "MSCorEE.dll", "long", "CorBindToRuntimeEx", "wstr", $sVersion, "ptr", NULL, "dword", 0, _
  865. "struct*", $tCLSID_CorRuntimeHost, "struct*", $tIID_ICorRuntimeHost, "ptr*", 0 )
  866. If Not ( @error = 0 And $aRet[0] = 0 And $aRet[6] ) Then Return SetError( 1,0,0 )
  867. $pRuntimeHost = $aRet[6]
  868. $oRuntimeHost = ObjCreateInterface( $pRuntimeHost, $sIID_ICorRuntimeHost, $sTag_ICorRuntimeHost )
  869. Return $oRuntimeHost
  870. EndFunc
  871. Func DotNet_StartDomain( ByRef $oAppDomain, $sFriendlyName = "", $sBaseDirectory = "" )
  872. Local $oDefDomain = DotNet_GetDefaultDomain()
  873. Local $pType, $oType
  874. $oDefDomain.GetType( $pType )
  875. $oType = ObjCreateInterface( $pType, $sIID__Type, $sTag__Type )
  876. Local $psaEmpty = SafeArrayCreateEmpty( $VT_VARIANT )
  877. Local $aArguments[5], $pSafeArray
  878. $aArguments[0] = $sFriendlyName
  879. $aArguments[2] = $sBaseDirectory
  880. $aArguments[4] = False
  881. AccVars_ArrayToSafeArray( $aArguments, $pSafeArray )
  882. $oType.InvokeMember_3( "CreateDomain", $BindingFlags_DefaultValue, $psaEmpty, $psaEmpty, $pSafeArray, $oAppDomain )
  883. EndFunc
  884. Func DotNet_StopDomain( ByRef $oAppDomain )
  885. Local $oRuntimeHost = DotNet_Start()
  886. $oRuntimeHost.UnloadDomain( Ptr( $oAppDomain ) )
  887. $oAppDomain = 0
  888. EndFunc
  889. ; Internal function
  890. Func DotNet_GetDefaultDomain()
  891. Static $pDefDomain = 0, $oDefDomain
  892. If $pDefDomain Then Return $oDefDomain
  893. Local $oRuntimeHost = DotNet_Start()
  894. $oRuntimeHost.Start()
  895. $oRuntimeHost.GetDefaultDomain( $pDefDomain )
  896. $oDefDomain = ObjCreateInterface( $pDefDomain, $sIID__AppDomain, $sTag__AppDomain )
  897. Return $oDefDomain
  898. EndFunc
  899. Func DotNet_LoadAssembly( $sAssemblyName, $oAppDomain = 0 )
  900. If Not $oAppDomain Then $oAppDomain = DotNet_GetDefaultDomain()
  901. Local $pType, $oType
  902. $oAppDomain.GetType( $pType )
  903. $oType = ObjCreateInterface( $pType, $sIID__Type, $sTag__Type )
  904. Local $pAssembly, $oAssembly
  905. $oType.get_Assembly( $pAssembly )
  906. $oAssembly = ObjCreateInterface( $pAssembly, $sIID__Assembly, $sTag__Assembly )
  907. Local $pAssemblyType, $oAssemblyType
  908. $oAssembly.GetType( $pAssemblyType )
  909. $oAssemblyType = ObjCreateInterface( $pAssemblyType, $sIID__Type, $sTag__Type )
  910. Local $aAssemblyName = [ $sAssemblyName ], $pSafeArray
  911. AccVars_ArrayToSafeArray( $aAssemblyName, $pSafeArray )
  912. Local $pNetCode
  913. $oAssemblyType.InvokeMember_3( "LoadFrom", $BindingFlags_DefaultValue, 0, 0, $pSafeArray, $pNetCode )
  914. ; We first try to load the .NET assembly with the LoadFrom method
  915. ; If LoadFrom method fails, we try to load the .NET assembly using the LoadWithPartialName method
  916. If Not Ptr( $pNetCode ) Then
  917. Local $iPos = StringInStr( $sAssemblyName, ".", Default, -1 )
  918. If StringRight( $sAssemblyName, StringLen( $sAssemblyName ) - $iPos ) = "dll" Then _ ; Use name of .NET assembly without DLL-
  919. $sAssemblyName = StringLeft( $sAssemblyName, $iPos - 1 ) ; extension in LoadWithPartialName method.
  920. $aAssemblyName[0] = $sAssemblyName
  921. AccVars_ArrayToSafeArray( $aAssemblyName, $pSafeArray )
  922. $oAssemblyType.InvokeMember_3( "LoadWithPartialName", $BindingFlags_DefaultValue, 0, 0, $pSafeArray, $pNetCode )
  923. ; LoadWithPartialName searches for the .NET assembly in the path given by $sBaseDirectory in DotNet_StartDomain
  924. EndIf
  925. If Not Ptr( $pNetCode ) Then Return SetError( 2,0,0 )
  926. Return ObjCreateInterface( $pNetCode, $sIID__Assembly, $sTag__Assembly )
  927. EndFunc
  928. Func DotNet_LoadCScode( $sCode, $sReferences = "", $oAppDomain = 0, $sFileName = "", $sCompilerOptions = "" )
  929. Local $oNetCode = DotNet_LoadCode( $sCode, $sReferences, "System", "Microsoft.CSharp.CSharpCodeProvider", $oAppDomain, $sFileName, $sCompilerOptions )
  930. If @error Then Return SetError( @error,0,0 )
  931. Return $oNetCode
  932. EndFunc
  933. Func DotNet_LoadVBcode( $sCode, $sReferences = "", $oAppDomain = 0, $sFileName = "", $sCompilerOptions = "" )
  934. Local $oNetCode = DotNet_LoadCode( $sCode, $sReferences, "System", "Microsoft.VisualBasic.VBCodeProvider", $oAppDomain, $sFileName, $sCompilerOptions )
  935. If @error Then Return SetError( @error,0,0 )
  936. Return $oNetCode
  937. EndFunc
  938. ; Internal function
  939. Func DotNet_LoadCode( $sCode, $sReferences, $sProviderAssembly, $sProviderType, $oAppDomain = 0, $sFileName = "", $sCompilerOptions = "" )
  940. If Not $oAppDomain Then $oAppDomain = DotNet_GetDefaultDomain()
  941. Local $oAsmProvider, $oCodeProvider, $oCodeCompiler, $oAsmSystem, $oPrms
  942. If IsObj( $oAppDomain ) Then $oAsmProvider = DotNet_LoadAssembly( $sProviderAssembly, $oAppDomain )
  943. If IsObj( $oAsmProvider ) Then $oAsmProvider.CreateInstance( $sProviderType, $oCodeProvider )
  944. If IsObj( $oCodeProvider ) Then $oCodeCompiler = $oCodeProvider.CreateCompiler()
  945. If IsObj( $oCodeCompiler ) Then $oAsmSystem = $sProviderAssembly = "System" ? $oAsmProvider : DotNet_LoadAssembly( "System", $oAppDomain )
  946. If Not IsObj( $oAsmSystem ) Then Return SetError( 3,0,0 )
  947. Local $aReferences = StringSplit( StringStripWS( StringRegExpReplace( $sReferences, "\s*\|\s*", "|" ), 3 ), "|", 2 ) ; 3 = $STR_STRIPLEADING + $STR_STRIPTRAILING, 2 = $STR_NOCOUNT
  948. Local $pSafeArray = AccVars_ArrayToSafeArrayOfVartype( $aReferences, $VT_BSTR )
  949. Local $psaVariant = AccVars_SafeArrayToSafeArrayOfVariant( $pSafeArray )
  950. Local $psaEmpty = SafeArrayCreateEmpty( $VT_VARIANT )
  951. ; Create $oPrms object
  952. $oAsmSystem.CreateInstance_3( "System.CodeDom.Compiler.CompilerParameters", True, 0, 0, $psaVariant, 0, $psaEmpty, $oPrms )
  953. If Not IsObj( $oPrms ) Then Return SetError( 4,0,0 )
  954. ; Set parameters for compiler
  955. $oPrms.OutputAssembly = $sFileName
  956. $oPrms.GenerateInMemory = ( $sFileName = "" )
  957. $oPrms.GenerateExecutable = ( StringRight( $sFileName, 4 ) = ".exe" )
  958. $oPrms.CompilerOptions = $sCompilerOptions
  959. $oPrms.IncludeDebugInformation = True
  960. ; Compile code
  961. Local $oCompilerRes = $oCodeCompiler.CompileAssemblyFromSource( $oPrms, $sCode )
  962. ; Compiler errors?
  963. If $oCompilerRes.Errors.Count() Then
  964. Local $b = False
  965. For $err In $oCompilerRes.Errors
  966. If $b Then ConsoleWrite( @CRLF )
  967. ConsoleWrite( "Line: " & $err.Line & @CRLF & "Column: " & $err.Column & @CRLF & $err.ErrorNumber & ": " & $err.ErrorText & @CRLF )
  968. $b = True
  969. Next
  970. Return SetError( 5,0,0 )
  971. EndIf
  972. If $sFileName Then
  973. Return $oCompilerRes.PathToAssembly()
  974. Else
  975. Local $pNetCode = $oCompilerRes.CompiledAssembly()
  976. Return ObjCreateInterface( $pNetCode, $sIID__Assembly, $sTag__Assembly )
  977. EndIf
  978. EndFunc
  979. Func DotNet_CreateObject( ByRef $oNetCode, $sClassName, $v3 = Default, $v4 = Default, $v5 = Default, $v6 = Default, $v7 = Default, $v8 = Default, $v9 = Default )
  980. Local $aParams = [ $v3, $v4, $v5, $v6, $v7, $v8, $v9 ], $oObject = 0
  981. If @NumParams = 2 Then
  982. $oNetCode.CreateInstance_2( $sClassName, True, $oObject )
  983. Return $oObject
  984. EndIf
  985. Local $iArgs = @NumParams - 2, $aArgs[$iArgs], $pSafeArray
  986. For $i = 0 To $iArgs - 1
  987. $aArgs[$i] = $aParams[$i]
  988. Next
  989. AccVars_ArrayToSafeArray( $aArgs, $pSafeArray )
  990. Local $psaEmpty = SafeArrayCreateEmpty( $VT_VARIANT )
  991. $oNetCode.CreateInstance_3( $sClassName, True, 0, 0, $pSafeArray, 0, $psaEmpty, $oObject )
  992. Return $oObject
  993. EndFunc
  994. ; ####################################################################################################
  995. ; ### ###
  996. ; ### DotNetUtils.au3 ###
  997. ; ### ###
  998. ; ####################################################################################################
  999. #include <Array.au3>
  1000. Func DotNet_ListDomains()
  1001. Local $pEnum, $pDomain, $oDomain
  1002. Local $aDomains[100][2], $iDomains = 0
  1003. Local $oRuntimeHost = DotNet_Start()
  1004. $oRuntimeHost.EnumDomains( $pEnum )
  1005. While Not $oRuntimeHost.NextDomain( $pEnum, $pDomain )
  1006. $oDomain = ObjCreateInterface( $pDomain, $sIID__AppDomain, $sTag__AppDomain )
  1007. $oDomain.get_FriendlyName( $aDomains[$iDomains][0] )
  1008. $oDomain.get_BaseDirectory( $aDomains[$iDomains][1] )
  1009. $iDomains += 1
  1010. WEnd
  1011. ReDim $aDomains[$iDomains][2]
  1012. Return $aDomains
  1013. EndFunc
  1014. Func DotNet_ListDomainsEx()
  1015. Local $aDomains = DotNet_ListDomains()
  1016. _ArrayDisplay( $aDomains, ".NET Framework Domains", "", 0, Default, "Friendly Name|Base Directory to load assemblies" )
  1017. EndFunc
  1018. Func DotNet_ListAssemblies( $oAppDomain = 0 )
  1019. Local $pAssemblies, $aAssemblies
  1020. If Not $oAppDomain Then _
  1021. $oAppDomain = DotNet_GetDefaultDomain()
  1022. $oAppDomain.getAssemblies( $pAssemblies )
  1023. AccVars_SafeArrayToArray( $pAssemblies, $aAssemblies )
  1024. Local $nAsms = UBound( $aAssemblies ), $aAsmInfo[$nAsms][3], $oAssembly
  1025. For $i = 0 To $nAsms - 1
  1026. $oAssembly = ObjCreateInterface( $aAssemblies[$i], $sIID__Assembly, $sTag__Assembly )
  1027. $oAssembly.get_GlobalAssemblyCache( $aAsmInfo[$i][0] )
  1028. $oAssembly.get_FullName( $aAsmInfo[$i][1] )
  1029. $oAssembly.get_Location( $aAsmInfo[$i][2] )
  1030. Next
  1031. Return $aAsmInfo
  1032. EndFunc
  1033. Func DotNet_ListAssembliesEx( $oAppDomain = 0 )
  1034. Local $aAssemblies = DotNet_ListAssemblies( $oAppDomain )
  1035. _ArrayDisplay( $aAssemblies, "Loaded Assemblies in Domain", "", 0, Default, "GAC|Assembly Full Name|Assembly Location" )
  1036. EndFunc