SafeArray.au3 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include-once
  2. Global Const $tagSAFEARRAYBOUND = _
  3. "ulong cElements;" & _ ; The number of elements in the dimension.
  4. "long lLbound;" ; The lower bound of the dimension.
  5. Global Const $tagSAFEARRAY = _
  6. "ushort cDims;" & _ ; The number of dimensions.
  7. "ushort fFeatures;" & _ ; Flags, see below.
  8. "ulong cbElements;" & _ ; The size of an array element.
  9. "ulong cLocks;" & _ ; The number of times the array has been locked without a corresponding unlock.
  10. "ptr pvData;" & _ ; The data.
  11. $tagSAFEARRAYBOUND ; One $tagSAFEARRAYBOUND for each dimension.
  12. ; fFeatures flags
  13. Global Const $FADF_AUTO = 0x0001 ; An array that is allocated on the stack.
  14. Global Const $FADF_STATIC = 0x0002 ; An array that is statically allocated.
  15. Global Const $FADF_EMBEDDED = 0x0004 ; An array that is embedded in a structure.
  16. Global Const $FADF_FIXEDSIZE = 0x0010 ; An array that may not be resized or reallocated.
  17. 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.
  18. 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.
  19. Global Const $FADF_HAVEVARTYPE = 0x0080 ; An array that has a variant type. The variant type can be retrieved with SafeArrayGetVartype.
  20. Global Const $FADF_BSTR = 0x0100 ; An array of BSTRs.
  21. Global Const $FADF_UNKNOWN = 0x0200 ; An array of IUnknown*.
  22. Global Const $FADF_DISPATCH = 0x0400 ; An array of IDispatch*.
  23. Global Const $FADF_VARIANT = 0x0800 ; An array of VARIANTs.
  24. Global Const $FADF_RESERVED = 0xF008 ; Bits reserved for future use.
  25. ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  26. ; Safearray functions
  27. ; Copied from AutoItObject.au3 by the AutoItObject-Team: monoceres, trancexx, Kip, ProgAndy
  28. ; https://www.autoitscript.com/forum/index.php?showtopic=110379
  29. Func SafeArrayCreate($vType, $cDims, $rgsabound)
  30. ; Author: Prog@ndy
  31. Local $aCall = DllCall("OleAut32.dll", "ptr", "SafeArrayCreate", "dword", $vType, "uint", $cDims, 'struct*', $rgsabound)
  32. If @error Then Return SetError(1, 0, 0)
  33. Return $aCall[0]
  34. EndFunc
  35. Func SafeArrayDestroy($pSafeArray)
  36. ; Author: Prog@ndy
  37. Local $aCall = DllCall("OleAut32.dll", "int", "SafeArrayDestroy", "ptr", $pSafeArray)
  38. If @error Then Return SetError(1, 0, 1)
  39. Return $aCall[0]
  40. EndFunc
  41. Func SafeArrayAccessData($pSafeArray, ByRef $pArrayData)
  42. ; Author: Prog@ndy
  43. Local $aCall = DllCall("OleAut32.dll", "int", "SafeArrayAccessData", "ptr", $pSafeArray, 'ptr*', 0)
  44. If @error Then Return SetError(1, 0, 1)
  45. $pArrayData = $aCall[2]
  46. Return $aCall[0]
  47. EndFunc
  48. Func SafeArrayUnaccessData($pSafeArray)
  49. ; Author: Prog@ndy
  50. Local $aCall = DllCall("OleAut32.dll", "int", "SafeArrayUnaccessData", "ptr", $pSafeArray)
  51. If @error Then Return SetError(1, 0, 1)
  52. Return $aCall[0]
  53. EndFunc
  54. Func SafeArrayGetUBound($pSafeArray, $iDim, ByRef $iBound)
  55. ; Author: Prog@ndy
  56. Local $aCall = DllCall("OleAut32.dll", "int", "SafeArrayGetUBound", "ptr", $pSafeArray, 'uint', $iDim, 'long*', 0)
  57. If @error Then Return SetError(1, 0, 1)
  58. $iBound = $aCall[3]
  59. Return $aCall[0]
  60. EndFunc
  61. Func SafeArrayGetLBound($pSafeArray, $iDim, ByRef $iBound)
  62. ; Author: Prog@ndy
  63. Local $aCall = DllCall("OleAut32.dll", "int", "SafeArrayGetLBound", "ptr", $pSafeArray, 'uint', $iDim, 'long*', 0)
  64. If @error Then Return SetError(1, 0, 1)
  65. $iBound = $aCall[3]
  66. Return $aCall[0]
  67. EndFunc
  68. Func SafeArrayGetDim($pSafeArray)
  69. Local $aResult = DllCall("OleAut32.dll", "uint", "SafeArrayGetDim", "ptr", $pSafeArray)
  70. If @error Then Return SetError(1, 0, 0)
  71. Return $aResult[0]
  72. EndFunc
  73. ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  74. Func SafeArrayCopy( $pSafeArrayIn, ByRef $pSafeArrayOut )
  75. Local $aRet = DllCall( "OleAut32.dll", "int", "SafeArrayCopy", "ptr", $pSafeArrayIn, "ptr*", 0 )
  76. If @error Then Return SetError(1,0,1)
  77. $pSafeArrayOut = $aRet[2]
  78. Return $aRet[0]
  79. EndFunc
  80. Func SafeArrayCreateEmpty( $vType )
  81. Local $tsaBound = DllStructCreate( $tagSAFEARRAYBOUND )
  82. DllStructSetData( $tsaBound, "cElements", 0 )
  83. DllStructSetData( $tsaBound, "lLbound", 0 )
  84. Return SafeArrayCreate( $vType, 0, $tsaBound )
  85. EndFunc
  86. Func SafeArrayDestroyData( $pSafeArray )
  87. Local $aRet = DllCall( "OleAut32.dll", "int", "SafeArrayDestroyData", "ptr", $pSafeArray )
  88. If @error Then Return SetError(1,0,1)
  89. Return $aRet[0]
  90. EndFunc
  91. Func SafeArrayGetVartype( $pSafeArray, ByRef $vt )
  92. Local $aRet = DllCall( "OleAut32.dll", "int", "SafeArrayGetVartype", "ptr", $pSafeArray, "ptr*", 0 )
  93. If @error Then Return SetError(1,0,1)
  94. $vt = $aRet[2]
  95. Return $aRet[0]
  96. EndFunc