Variant.au3 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #include-once
  2. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  3. ; Copied from AutoItObject.au3 by the AutoItObject-Team: monoceres, trancexx, Kip, ProgAndy
  4. ; https://www.autoitscript.com/forum/index.php?showtopic=110379
  5. Global Const $tagVARIANT = "word vt;word r1;word r2;word r3;ptr data; ptr"
  6. ; The structure takes up 16/24 bytes when running 32/64 bit
  7. ; Space for the data element at the end represents 2 pointers
  8. ; This is 8 bytes running 32 bit and 16 bytes running 64 bit
  9. Global Const $VT_EMPTY = 0 ; 0x0000
  10. Global Const $VT_NULL = 1 ; 0x0001
  11. Global Const $VT_I2 = 2 ; 0x0002
  12. Global Const $VT_I4 = 3 ; 0x0003
  13. Global Const $VT_R4 = 4 ; 0x0004
  14. Global Const $VT_R8 = 5 ; 0x0005
  15. Global Const $VT_CY = 6 ; 0x0006
  16. Global Const $VT_DATE = 7 ; 0x0007
  17. Global Const $VT_BSTR = 8 ; 0x0008
  18. Global Const $VT_DISPATCH = 9 ; 0x0009
  19. Global Const $VT_ERROR = 10 ; 0x000A
  20. Global Const $VT_BOOL = 11 ; 0x000B
  21. Global Const $VT_VARIANT = 12 ; 0x000C
  22. Global Const $VT_UNKNOWN = 13 ; 0x000D
  23. Global Const $VT_DECIMAL = 14 ; 0x000E
  24. Global Const $VT_I1 = 16 ; 0x0010
  25. Global Const $VT_UI1 = 17 ; 0x0011
  26. Global Const $VT_UI2 = 18 ; 0x0012
  27. Global Const $VT_UI4 = 19 ; 0x0013
  28. Global Const $VT_I8 = 20 ; 0x0014
  29. Global Const $VT_UI8 = 21 ; 0x0015
  30. Global Const $VT_INT = 22 ; 0x0016
  31. Global Const $VT_UINT = 23 ; 0x0017
  32. Global Const $VT_VOID = 24 ; 0x0018
  33. Global Const $VT_HRESULT = 25 ; 0x0019
  34. Global Const $VT_PTR = 26 ; 0x001A
  35. Global Const $VT_SAFEARRAY = 27 ; 0x001B
  36. Global Const $VT_CARRAY = 28 ; 0x001C
  37. Global Const $VT_USERDEFINED = 29 ; 0x001D
  38. Global Const $VT_LPSTR = 30 ; 0x001E
  39. Global Const $VT_LPWSTR = 31 ; 0x001F
  40. Global Const $VT_RECORD = 36 ; 0x0024
  41. Global Const $VT_INT_PTR = 37 ; 0x0025
  42. Global Const $VT_UINT_PTR = 38 ; 0x0026
  43. Global Const $VT_FILETIME = 64 ; 0x0040
  44. Global Const $VT_BLOB = 65 ; 0x0041
  45. Global Const $VT_STREAM = 66 ; 0x0042
  46. Global Const $VT_STORAGE = 67 ; 0x0043
  47. Global Const $VT_STREAMED_OBJECT = 68 ; 0x0044
  48. Global Const $VT_STORED_OBJECT = 69 ; 0x0045
  49. Global Const $VT_BLOB_OBJECT = 70 ; 0x0046
  50. Global Const $VT_CF = 71 ; 0x0047
  51. Global Const $VT_CLSID = 72 ; 0x0048
  52. Global Const $VT_VERSIONED_STREAM = 73 ; 0x0049
  53. Global Const $VT_BSTR_BLOB = 0xFFF
  54. Global Const $VT_VECTOR = 0x1000
  55. Global Const $VT_ARRAY = 0x2000
  56. Global Const $VT_BYREF = 0x4000
  57. Global Const $VT_RESERVED = 0x8000
  58. Global Const $VT_ILLEGAL = 0xFFFF
  59. Global Const $VT_ILLEGALMASKED = 0xFFF
  60. Global Const $VT_TYPEMASK = 0xFFF
  61. ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  62. ;Global Const $tagVARIANT = "word vt;word r1;word r2;word r3;ptr data; ptr"
  63. ; The structure takes up 16/24 bytes when running 32/64 bit
  64. ; Space for the data element at the end represents 2 pointers
  65. ; This is 8 bytes running 32 bit and 16 bytes running 64 bit
  66. #cs
  67. DECIMAL structure
  68. https://msdn.microsoft.com/en-us/library/windows/desktop/ms221061(v=vs.85).aspx
  69. From oledb.h:
  70. typedef struct tagDEC {
  71. USHORT wReserved; ; vt, 2 bytes
  72. union { ; r1, 2 bytes
  73. struct {
  74. BYTE scale;
  75. BYTE sign;
  76. };
  77. USHORT signscale;
  78. };
  79. ULONG Hi32; ; r2, r3, 4 bytes
  80. union { ; data, 8 bytes
  81. struct {
  82. #ifdef _MAC
  83. ULONG Mid32;
  84. ULONG Lo32;
  85. #else
  86. ULONG Lo32;
  87. ULONG Mid32;
  88. #endif
  89. };
  90. ULONGLONG Lo64;
  91. };
  92. } DECIMAL;
  93. #ce
  94. Global Const $tagDEC = "word wReserved;byte scale;byte sign;uint Hi32;uint Lo32;uint Mid32"
  95. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  96. ; Variant functions
  97. ; Copied from AutoItObject.au3 by the AutoItObject-Team: monoceres, trancexx, Kip, ProgAndy
  98. ; https://www.autoitscript.com/forum/index.php?showtopic=110379
  99. ; #FUNCTION# ====================================================================================================================
  100. ; Name...........: VariantClear
  101. ; Description ...: Clears the value of a variant
  102. ; Syntax.........: VariantClear($pvarg)
  103. ; Parameters ....: $pvarg - the VARIANT to clear
  104. ; Return values .: Success - 0
  105. ; Failure - nonzero
  106. ; Author ........: Prog@ndy
  107. ; Modified.......:
  108. ; Remarks .......:
  109. ; Related .......: VariantFree
  110. ; Link ..........: http://msdn.microsoft.com/en-us/library/ms221165.aspx
  111. ; Example .......:
  112. ; ===============================================================================================================================
  113. Func VariantClear($pvarg)
  114. ; Author: Prog@ndy
  115. Local $aCall = DllCall("OleAut32.dll", "long", "VariantClear", "ptr", $pvarg)
  116. If @error Then Return SetError(1, 0, 1)
  117. Return $aCall[0]
  118. EndFunc
  119. ; #FUNCTION# ====================================================================================================================
  120. ; Name...........: VariantCopy
  121. ; Description ...: Copies a VARIANT to another
  122. ; Syntax.........: VariantCopy($pvargDest, $pvargSrc)
  123. ; Parameters ....: $pvargDest - Destionation variant
  124. ; $pvargSrc - Source variant
  125. ; Return values .: Success - 0
  126. ; Failure - nonzero
  127. ; Author ........: Prog@ndy
  128. ; Modified.......:
  129. ; Remarks .......:
  130. ; Related .......: VariantRead
  131. ; Link ..........: http://msdn.microsoft.com/en-us/library/ms221697.aspx
  132. ; Example .......:
  133. ; ===============================================================================================================================
  134. Func VariantCopy($pvargDest, $pvargSrc)
  135. ; Author: Prog@ndy
  136. Local $aCall = DllCall("OleAut32.dll", "long", "VariantCopy", "ptr", $pvargDest, 'ptr', $pvargSrc)
  137. If @error Then Return SetError(1, 0, 1)
  138. Return $aCall[0]
  139. EndFunc
  140. ; #FUNCTION# ====================================================================================================================
  141. ; Name...........: VariantInit
  142. ; Description ...: Initializes a variant.
  143. ; Syntax.........: VariantInit($pvarg)
  144. ; Parameters ....: $pvarg - the VARIANT to initialize
  145. ; Return values .: Success - 0
  146. ; Failure - nonzero
  147. ; Author ........: Prog@ndy
  148. ; Modified.......:
  149. ; Remarks .......:
  150. ; Related .......: VariantClear
  151. ; Link ..........: http://msdn.microsoft.com/en-us/library/ms221402.aspx
  152. ; Example .......:
  153. ; ===============================================================================================================================
  154. Func VariantInit($pvarg)
  155. ; Author: Prog@ndy
  156. Local $aCall = DllCall("OleAut32.dll", "long", "VariantInit", "ptr", $pvarg)
  157. If @error Then Return SetError(1, 0, 1)
  158. Return $aCall[0]
  159. EndFunc
  160. ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  161. Func VariantChangeType( $pVarDest, $pVarSrc, $wFlags, $vt )
  162. Local $aRet = DllCall( "OleAut32.dll", "long", "VariantChangeType", "ptr", $pVarDest, "ptr", $pVarSrc, "word", $wFlags, "word", $vt )
  163. If @error Then Return SetError(1,0,1)
  164. Return $aRet[0]
  165. EndFunc
  166. Func VariantChangeTypeEx( $pVarDest, $pVarSrc, $lcid, $wFlags, $vt )
  167. Local $aRet = DllCall( "OleAut32.dll", "long", "VariantChangeTypeEx", "ptr", $pVarDest, "ptr", $pVarSrc, "word", $lcid, "word", $wFlags, "word", $vt )
  168. If @error Then Return SetError(1,0,1)
  169. Return $aRet[0]
  170. EndFunc
  171. Func VarAdd( $pVarLeft, $pVarRight, $pVarResult )
  172. Local $aRet = DllCall( "OleAut32.dll", "long", "VarAdd", "ptr", $pVarLeft, "ptr", $pVarRight, "ptr", $pVarResult )
  173. If @error Then Return SetError(1,0,1)
  174. Return $aRet[0]
  175. EndFunc
  176. Func VarSub( $pVarLeft, $pVarRight, $pVarResult )
  177. Local $aRet = DllCall( "OleAut32.dll", "long", "VarSub", "ptr", $pVarLeft, "ptr", $pVarRight, "ptr", $pVarResult )
  178. If @error Then Return SetError(1,0,1)
  179. Return $aRet[0]
  180. EndFunc
  181. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  182. ; BSTR (basic string) functions
  183. ; Copied from AutoItObject.au3 by the AutoItObject-Team: monoceres, trancexx, Kip, ProgAndy
  184. ; https://www.autoitscript.com/forum/index.php?showtopic=110379
  185. Func SysAllocString( $str )
  186. Local $aRet = DllCall( "OleAut32.dll", "ptr", "SysAllocString", "wstr", $str )
  187. If @error Then Return SetError(1, 0, 0)
  188. Return $aRet[0]
  189. EndFunc
  190. Func SysFreeString( $pBSTR )
  191. If Not $pBSTR Then Return SetError(1, 0, 0)
  192. DllCall( "OleAut32.dll", "none", "SysFreeString", "ptr", $pBSTR )
  193. If @error Then Return SetError(2, 0, 0)
  194. EndFunc
  195. Func SysReadString( $pBSTR, $iLen = -1 )
  196. If Not $pBSTR Then Return SetError(1, 0, "")
  197. If $iLen < 1 Then $iLen = SysStringLen( $pBSTR )
  198. If $iLen < 1 Then Return SetError(2, 0, "")
  199. Return DllStructGetData( DllStructCreate( "wchar[" & $iLen & "]", $pBSTR ), 1 )
  200. EndFunc
  201. Func SysStringLen( $pBSTR )
  202. If Not $pBSTR Then Return SetError(1, 0, 0)
  203. Local $aRet = DllCall( "OleAut32.dll", "uint", "SysStringLen", "ptr", $pBSTR )
  204. If @error Then Return SetError(2, 0, 0)
  205. Return $aRet[0]
  206. EndFunc
  207. ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<