Sign in to follow this  
Followers 0
wolf9228

Array of data structures

1 post in this topic

#1 ·  Posted (edited)

by this project, you can create a Array of data structures and control Array easily

project File

MemArray.zip

Modification To the best

New project File

NewMemArray.zip

 example Links

PARAMDATA structure
http://msdn.microsoft.com/en-us/library/windows/desktop/ms221100%28v=vs.85%29.aspx

METHODDATA structure
http://msdn.microsoft.com/en-us/library/windows/desktop/ms221359%28v=vs.85%29.aspx

INTERFACEDATA structure

http://msdn.microsoft.com/en-us/library/windows/desktop/ms221164%28v=vs.85%29.aspx

CreateDispTypeInfo function
http://msdn.microsoft.com/en-us/library/windows/desktop/ms221237%28v=vs.85%29.aspx

DispGetIDsOfNames function
http://msdn.microsoft.com/en-us/library/windows/desktop/ms221309%28v=vs.85%29.aspx

MemArray.au3

#include <Memory.au3>
#include <Array.au3>
Global $PtrSize = DllStructGetSize(DllStructCreate("ptr"))

Global $CC_FASTCALL = 0
Global $CC_CDECL = 1
Global $CC_MSCPASCAL = $CC_CDECL + 1
Global $CC_PASCAL = $CC_MSCPASCAL
Global $CC_MACPASCAL = $CC_PASCAL + 1
Global $CC_STDCALL = $CC_MACPASCAL + 1
Global $CC_FPFASTCALL = $CC_STDCALL + 1
Global $CC_SYSCALL = $CC_FPFASTCALL + 1
Global $CC_MPWCDECL = $CC_SYSCALL + 1
Global $CC_MPWPASCAL = $CC_MPWCDECL + 1
Global $CC_MAX = $CC_MPWPASCAL + 1
;wFlags MemberType
Global $DISPATCH_METHOD = 0x1, _
$DISPATCH_PROPERTYGET = 0x2 , _
$DISPATCH_PROPERTYPUT = 0x4 , _
$DISPATCH_PROPERTYPUTREF = 0x8
;wFlags MemberType

;PARAMDATA structure
;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221100%28v=vs.85%29.aspx

;METHODDATA structure
;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221359%28v=vs.85%29.aspx

;INTERFACEDATA structure
;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221164%28v=vs.85%29.aspx

;CreateDispTypeInfo function
;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221237%28v=vs.85%29.aspx

;DispGetIDsOfNames function
;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221309%28v=vs.85%29.aspx

;by this project, you can create a Array of data structures and control Array easily

Dim $MaxLen = 10
$PszName = "WCHAR szName[" & $MaxLen & "]"
$PszNameArray = StrucMemArray(3,$PszName)
SSetAt($PszNameArray,0,"NumberA","szName")
SSetAt($PszNameArray,1,"NumberB","szName")
SSetAt($PszNameArray,2,"NumberC","szName")
$NumberAPtr = SGetAt($PszNameArray,0,"szName")
$NumberBPtr = SGetAt($PszNameArray,1,"szName")
$NumberCPtr = SGetAt($PszNameArray,2,"szName")

$tagPARAMDATA = "ptr szName;WORD vt"
$ParamDataArray = StrucMemArray(3,$tagPARAMDATA)

;------------Row 0----------------------------
SSetAt($ParamDataArray,0,$NumberAPtr,"szName")
SSetAt($ParamDataArray,0,23,"vt")
;------------Row 0----------------------------

;------------Row 1----------------------------
SSetAt($ParamDataArray,1,$NumberBPtr,"szName")
SSetAt($ParamDataArray,1,23,"vt")
;------------Row 1----------------------------

;------------Row 2----------------------------
SSetAt($ParamDataArray,2,$NumberCPtr,"szName")
SSetAt($ParamDataArray,2,23,"vt")
;------------Row 2----------------------------

$DataArray = StrucMemArrayGet_DataArray($ParamDataArray)
_ArrayDisplay($DataArray,"ParamDataArray")

$ParamBuffer = SGetBuffer($ParamDataArray)
$MszName = "WCHAR szName[" & $MaxLen & "]"
$MszNameArray = StrucMemArray(3,$MszName)
SSetAt($MszNameArray,0,"METHODA","szName")
SSetAt($MszNameArray,1,"METHODB","szName")
SSetAt($MszNameArray,2,"METHODC","szName")
$METHODAPtr = SGetAt($MszNameArray,0,"szName")
$METHODBPtr = SGetAt($MszNameArray,1,"szName")
$METHODCPtr = SGetAt($MszNameArray,2,"szName")


$tagMethodData = "ptr szName;ptr ppdata;UINT dispid;UINT iMeth;UINT cc;UINT cArgs;WORD wFlags;WORD vtReturn;"
$MethodDataArray = StrucMemArray(3,$tagMethodData)
;------------Row 0----------------------------
SSetAt($MethodDataArray,0,$METHODAPtr,"szName")
SSetAt($MethodDataArray,0,$ParamBuffer,"ppdata")
SSetAt($MethodDataArray,0,1,"dispid")
SSetAt($MethodDataArray,0,0,"iMeth")
SSetAt($MethodDataArray,0,$CC_STDCALL,"cc")
SSetAt($MethodDataArray,0,3,"cArgs")
SSetAt($MethodDataArray,0,$DISPATCH_METHOD,"wFlags")
SSetAt($MethodDataArray,0,23,"vtReturn")
;------------Row 0----------------------------

;------------Row 1----------------------------
SSetAt($MethodDataArray,1,$METHODBPtr,"szName")
SSetAt($MethodDataArray,1,$ParamBuffer,"ppdata")
SSetAt($MethodDataArray,1,2,"dispid")
SSetAt($MethodDataArray,1,1,"iMeth")
SSetAt($MethodDataArray,1,$CC_STDCALL,"cc")
SSetAt($MethodDataArray,1,3,"cArgs")
SSetAt($MethodDataArray,1,$DISPATCH_METHOD,"wFlags")
SSetAt($MethodDataArray,1,23,"vtReturn")
;------------Row 1----------------------------

;------------Row 2----------------------------
SSetAt($MethodDataArray,2,$METHODCPtr,"szName")
SSetAt($MethodDataArray,2,$ParamBuffer,"ppdata")
SSetAt($MethodDataArray,2,3,"dispid")
SSetAt($MethodDataArray,2,2,"iMeth")
SSetAt($MethodDataArray,2,$CC_STDCALL,"cc")
SSetAt($MethodDataArray,2,3,"cArgs")
SSetAt($MethodDataArray,2,$DISPATCH_METHOD,"wFlags")
SSetAt($MethodDataArray,2,23,"vtReturn")
;------------Row 2----------------------------
$DataArray = StrucMemArrayGet_DataArray($MethodDataArray)
_ArrayDisplay($DataArray,"MethodDataArray")

$tagInterfacedata = "ptr MethodData;UINT cMembers"
$Interfacedata = DllStructCreate($tagInterfacedata)
SSetBufferToStructElement($MethodDataArray,$Interfacedata,"MethodData")
DllStructSetData($Interfacedata,"cMembers",3)

$pptinfo = CreateDispTypeInfo($Interfacedata)
$rgszNamesSt = DllStructCreate("ptr")
DllStructSetData($rgszNamesSt,1,$METHODAPtr)
$Id = DispGetIDsOfNames($pptinfo,DllStructGetPtr($rgszNamesSt))
MsgBox(0,"Msg","ID Of METHODA Is " & $Id)

DllStructSetData($rgszNamesSt,1,$METHODBPtr)
$Id = DispGetIDsOfNames($pptinfo,DllStructGetPtr($rgszNamesSt))
MsgBox(0,"Msg","ID Of METHODB Is " & $Id)

DllStructSetData($rgszNamesSt,1,$METHODCPtr)
$Id = DispGetIDsOfNames($pptinfo,DllStructGetPtr($rgszNamesSt))
MsgBox(0,"Msg","ID Of METHODC Is " & $Id)

Func StrucMemArray($RowsCount,$DataType)
Local $SizeOfType = DllStructGetSize(DllStructCreate($DataType))
if @error Then Return SetError(1,0,0)
Select
Case $RowsCount < 1
Return SetError(2,0,0)
Case Else
Local $SizeOfData = ($RowsCount * $SizeOfType)
Local $Len = (StringLen($DataType) + 1) , $StrucMemArray = 0
$StrucMemArray = DllStructCreate("PTR DATAPTR;INT ISSTRUCT;CHAR TYPE["&$Len&"];INT SIZE;INT RE;BYTE DATA[" & $SizeOfData & "]")
if @error Then Return SetError(3,0,0)
DllStructSetData($StrucMemArray,"ISSTRUCT",IstagStruct($DataType))
DllStructSetData($StrucMemArray,"TYPE",$DataType)
DllStructSetData($StrucMemArray,"SIZE",$SizeOfType)
DllStructSetData($StrucMemArray,"RE",$RowsCount)
Return SetError(0,0,$StrucMemArray)
EndSelect
EndFunc

Func SGetBuffer($StrucMemArray)
If Not IsDllStruct($StrucMemArray) Then Return SetError(1,0,0)
Local $DataPtr = DllStructGetData($StrucMemArray,"DATAPTR")
if @error Then Return SetError(2,0,0)
if Not($DataPtr) Then $DataPtr = SGetDataPtr($StrucMemArray)
if @error Then Return SetError(3,0,0)
Return SetError(0,0,$DataPtr)
EndFunc

Func SAttachBuffer($StrucMemArray,$BufferPtr)
If Not IsDllStruct($StrucMemArray) Then Return SetError(1,0,False)
Local $SizeOfType = DllStructGetData($StrucMemArray,"SIZE")
if @error Then Return SetError(2,0,False)
Local $RowsCount = DllStructGetData($StrucMemArray,"RE")
if @error Then Return SetError(3,0,False)
Local $DataPtr = SGetDataPtr($StrucMemArray)
if @error Then Return SetError(4,0,False)
_MemMoveMemory($BufferPtr,$DataPtr,($SizeOfType * $RowsCount))
DllStructSetData($StrucMemArray,"DATAPTR",$BufferPtr)
Return SetError(0,0,True)
EndFunc

Func SGetBufferSize($StrucMemArray)
If Not IsDllStruct($StrucMemArray) Then Return SetError(1,0,0)
Local $SizeOfType = DllStructGetData($StrucMemArray,"SIZE")
if @error Then Return SetError(2,0,0)
Local $RowsCount = DllStructGetData($StrucMemArray,"RE")
if @error Then Return SetError(3,0,0)
Return SetError(0,0,($SizeOfType * $RowsCount))
EndFunc

Func SGetBufferTag($StrucMemArray,$ElementName = "ByteMemArray")
If Not IsDllStruct($StrucMemArray) Then Return SetError(1,0,0)
Local $SizeOfType = DllStructGetData($StrucMemArray,"SIZE")
if @error Then Return SetError(2,0,0)
Local $RowsCount = DllStructGetData($StrucMemArray,"RE")
if @error Then Return SetError(3,0,0)
Local $BufferTag = String("BYTE " & $ElementName & "[" & ($SizeOfType * $RowsCount) & "]")
Return SetError(0,0,$BufferTag)
EndFunc

Func SSetBufferToStructElement($StrucMemArray,$Struct,$StructElement,$ElementIndex = 0)
; $ElementIndex can be 0
If Not IsDllStruct($StrucMemArray) Or Not IsDllStruct($Struct) Then Return SetError(1,0,False)
Local $DataPtr = DllStructGetData($StrucMemArray,"DATAPTR")
if @error Then Return SetError(2,0,False)
if Not($DataPtr) Then $DataPtr = SGetDataPtr($StrucMemArray)
if @error Then Return SetError(3,0,False)
Switch $ElementIndex
Case 0
DllStructSetData($Struct,$StructElement,$DataPtr)
if @error Then Return SetError(4,0,False)
Case Else
DllStructSetData($Struct,$StructElement,$DataPtr,$ElementIndex)
if @error Then Return SetError(5,0,False)
EndSwitch
DllStructSetData($StrucMemArray,"DATAPTR",$DataPtr)
if @error Then Return SetError(6,0,False)
Return SetError(0,0,True)
EndFunc

Func SCopyBufferToStructElement($StrucMemArray,$Struct,$StructElement)
If Not IsDllStruct($StrucMemArray) Or Not IsDllStruct($Struct) Then Return SetError(1,0,False)
Local $DataPtr = DllStructGetData($StrucMemArray,"DATAPTR")
if @error Then Return SetError(2,0,False)
if Not($DataPtr) Then $DataPtr = SGetDataPtr($StrucMemArray)
if @error Then Return SetError(3,0,False)
Local $StructElementPtr = DllStructGetPtr($Struct,$StructElement)
if @error Then Return SetError(4,0,False)
Local $SizeOfType = DllStructGetData($StrucMemArray,"SIZE")
if @error Then Return SetError(5,0,False)
Local $RowsCount = DllStructGetData($StrucMemArray,"RE")
if @error Then Return SetError(6,0,False)
_MemMoveMemory($DataPtr,$StructElementPtr,($SizeOfType * $RowsCount))
DllStructSetData($StrucMemArray,"DATAPTR",$StructElementPtr)
if @error Then Return SetError(7,0,False)
Return SetError(0,0,True)
EndFunc

Func SUBound($StrucMemArray)
If Not IsDllStruct($StrucMemArray) Then Return SetError(1,0,0)
Local $RowsCount = DllStructGetData($StrucMemArray,"RE")
if @error Then Return SetError(2,0,0)
Return SetError(0,0,$RowsCount)
EndFunc

Func SDeleteStrucMemArray(ByRef $StrucMemArray)
$StrucMemArray = ""
EndFunc

Func SGetAt($StrucMemArray,$RowIndex,$Element = "",$ElementIndex = 0)
; $Element And $ElementIndex Only use If $DataType Is tagStruct
If Not IsDllStruct($StrucMemArray) Then Return SetError(1,0,"")
Local $iRowsCount = SUBound($StrucMemArray) , $Value
If ($RowIndex < 0 Or $RowIndex > ($iRowsCount -1)) Then Return SetError(2,0,"")
Local $SizeOfType = DllStructGetData($StrucMemArray,"SIZE")
if @error Then Return SetError(3,0,"")
Local $DataType = DllStructGetData($StrucMemArray,"TYPE")
if @error Then Return SetError(4,0,"")
Local $IsStruct = DllStructGetData($StrucMemArray,"ISSTRUCT")
if @error Then Return SetError(5,0,"")
Local $DataPtr = DllStructGetData($StrucMemArray,"DATAPTR")
if @error Then Return SetError(6,0,"")
if ($DataPtr) Then $DataPtr = SMoveDataPtr($DataPtr,($SizeOfType * $RowIndex))
if Not($DataPtr) Then $DataPtr = SGetDataPtr($StrucMemArray,$RowIndex)
if @error Then Return SetError(7,0,"")
if ($IsStruct) Then
Switch $Element
Case ""
$Value = DllStructCreate($DataType,$DataPtr)
if @error Then Return SetError(8,0,"")
Case Else
Switch $ElementIndex
Case 0
DllStructGetData(DllStructCreate($DataType,$DataPtr),$Element,2)
If (Not(@error)) Then
$Value =  DllStructGetPtr(DllStructCreate($DataType,$DataPtr),$Element)
if @error Then Return SetError(9,0,"")
Else
$Value =  DllStructGetData(DllStructCreate($DataType,$DataPtr),$Element)
if @error Then Return SetError(10,0,"")
EndIf
Case Else
$Value =  DllStructGetData(DllStructCreate($DataType,$DataPtr),$Element,$ElementIndex)
if @error Then Return SetError(11,0,"")
EndSwitch
EndSwitch
Else
$Value = DllStructGetData(DllStructCreate($DataType,$DataPtr),1)
if @error Then Return SetError(12,0,"")
EndIf
Return SetError(0,0,$Value)
EndFunc

Func SSetAt($StrucMemArray,$RowIndex,$vValue,$Element = "",$ElementIndex = 0)
; $Element And $ElementIndex Only use If $DataType Is tagStruct
; $vValue Must be Ptr Or Struct if $Element = "" And $DataType Is tagStruct
If Not IsDllStruct($StrucMemArray) Or Not IsMemDataType($vValue) Then Return SetError(1,0,False)
Local $iRowsCount = SUBound($StrucMemArray),$Value
If ($RowIndex < 0 Or $RowIndex > ($iRowsCount -1)) Then Return SetError(2,0,False)
Local $SizeOfType = DllStructGetData($StrucMemArray,"SIZE")
if @error Then Return SetError(3,0,False)
Local $DataType = DllStructGetData($StrucMemArray,"TYPE")
if @error Then Return SetError(4,0,False)
Local $IsStruct = DllStructGetData($StrucMemArray,"ISSTRUCT")
if @error Then Return SetError(5,0,False)
Local $DataPtr = DllStructGetData($StrucMemArray,"DATAPTR")
if @error Then Return SetError(6,0,False)
if ($DataPtr) Then $DataPtr = SMoveDataPtr($DataPtr,($SizeOfType * $RowIndex))
if Not($DataPtr) Then $DataPtr = SGetDataPtr($StrucMemArray,$RowIndex)
if @error Then Return SetError(7,0,False)
if ($IsStruct) Then
Switch $Element
Case ""
$Value = $vValue
if IsDllStruct($vValue) Then $Value = DllStructGetPtr($vValue)
if Not IsPtr($Value) Or $Value = Ptr(0) Then Return SetError(8,0,False)
_MemMoveMemory($Value,$DataPtr,$SizeOfType)
Case Else
Switch $ElementIndex
Case 0
DllStructSetData(DllStructCreate($DataType,$DataPtr),$Element,$vValue)
if @error Then Return SetError(9,0,False)
Case Else
DllStructSetData(DllStructCreate($DataType,$DataPtr),$Element,$vValue,$ElementIndex)
if @error Then Return SetError(10,0,False)
EndSwitch
EndSwitch
Else
DllStructSetData(DllStructCreate($DataType,$DataPtr),1,$vValue)
if @error Then Return SetError(11,0,False)
EndIf
Return SetError(0,0,True)
EndFunc

Func SGetDataPtr($StrucMemArray,$RowIndex = 0)
If Not IsDllStruct($StrucMemArray) Then Return SetError(1,0,0)
Local $RowsCount = SUBound($StrucMemArray)
If ($RowIndex < 0 Or $RowIndex > ($RowsCount -1)) Then Return SetError(2,0,0)
Local $SizeOfType = DllStructGetData($StrucMemArray,"SIZE")
if @error Then Return SetError(3,0,0)
Local $DataPtr = DllStructGetPtr($StrucMemArray,"DATA")
$DataPtr = SMoveDataPtr($DataPtr,($RowIndex * $SizeOfType))
Return SetError(0,0,$DataPtr)
EndFunc

Func SMoveDataPtr($DataPtr,$MovPos)
Return ($DataPtr + $MovPos)
EndFunc

Func PtrMemArray($RowsCount,$DataType)
Local $SizeOfType = DllStructGetSize(DllStructCreate($DataType))
if @error Then Return SetError(1,0,0)
Select
Case $RowsCount < 1
Return SetError(2,0,0)
Case Else
Local $Len = (StringLen($DataType) + 1) , $PtrMemArray = 0
$PtrMemArray = DllStructCreate("INT ISSTRUCT;CHAR TYPE["&$Len&"];INT SIZE;INT RE;PTR ARRAY[" & $RowsCount & "]")
if @error Then Return SetError(3,0,0)
DllStructSetData($PtrMemArray,"ISSTRUCT",IstagStruct($DataType))
DllStructSetData($PtrMemArray,"TYPE",$DataType)
DllStructSetData($PtrMemArray,"SIZE",$SizeOfType)
DllStructSetData($PtrMemArray,"RE",$RowsCount)
For $i = 1 To $RowsCount
$Alloc = Alloc($SizeOfType)
DllStructSetData($PtrMemArray,"ARRAY",$Alloc,$i)
Next
Return SetError(0,0,$PtrMemArray)
EndSelect
EndFunc

Func PGetBuffer($PtrMemArray)
If Not IsDllStruct($PtrMemArray) Then Return SetError(1,0,0)
Local $ArrayPtr = PGetArrayPtr($PtrMemArray)
if @error Then Return SetError(2,0,0)
Return SetError(0,0,$ArrayPtr)
EndFunc

Func PAttachBuffer($PtrMemArray,$BufferPtr)
If Not IsDllStruct($PtrMemArray) Then Return SetError(1,0,False)
Local $ArrayPtr = PGetArrayPtr($PtrMemArray)
if @error Then Return SetError(2,0,False)
Local $RowsCount = DllStructGetData($PtrMemArray,"RE")
if @error Then Return SetError(3,0,False)
PFreePtrMemArray($PtrMemArray)
if @error Then Return SetError(4,0,False)
_MemMoveMemory($BufferPtr,$ArrayPtr,($PtrSize * $RowsCount))
Return SetError(0,0,True)
EndFunc

Func PGetBufferSize($PtrMemArray)
If Not IsDllStruct($PtrMemArray) Then Return SetError(1,0,0)
Local $RowsCount = DllStructGetData($PtrMemArray,"RE")
if @error Then Return SetError(2,0,0)
Return SetError(0,0,($PtrSize * $RowsCount))
EndFunc

Func PGetBufferTag($PtrMemArray,$ElementName = "PtrMemArray")
If Not IsDllStruct($PtrMemArray) Then Return SetError(1,0,0)
Local $RowsCount = DllStructGetData($PtrMemArray,"RE")
if @error Then Return SetError(2,0,0)
Local $BufferTag = String("PTR " & $ElementName & "[" & ($RowsCount) & "]")
Return SetError(0,0,$BufferTag)
EndFunc

Func PSetBufferToStructElement($PtrMemArray,$Struct,$StructElement,$ElementIndex = 0)
; $ElementIndex can be 0
If Not IsDllStruct($PtrMemArray) Or Not IsDllStruct($Struct) Then Return SetError(1,0,False)
Local $ArrayPtr = PGetArrayPtr($PtrMemArray)
if @error Then Return SetError(2,0,False)
Switch $ElementIndex
Case 0
DllStructSetData($Struct,$StructElement,$ArrayPtr)
if @error Then Return SetError(3,0,False)
Case Else
DllStructSetData($Struct,$StructElement,$ArrayPtr,$ElementIndex)
if @error Then Return SetError(4,0,False)
EndSwitch
Return SetError(0,0,True)
EndFunc

Func PCopyBufferToStructElement($PtrMemArray,$Struct,$StructElement)
If Not IsDllStruct($PtrMemArray) Or Not IsDllStruct($Struct) Then Return SetError(1,0,False)
Local $ArrayPtr = PGetArrayPtr($PtrMemArray)
if @error Then Return SetError(2,0,False)
Local $StructElementPtr = DllStructGetPtr($Struct,$StructElement)
if @error Then Return SetError(3,0,False)
Local $RowsCount = DllStructGetData($PtrMemArray,"RE")
if @error Then Return SetError(4,0,False)
_MemMoveMemory($ArrayPtr,$StructElementPtr,($PtrSize * $RowsCount))
Return SetError(0,0,True)
EndFunc

Func PUBound($PtrMemArray)
If Not IsDllStruct($PtrMemArray) Then Return SetError(1,0,0)
Local $RowsCount = DllStructGetData($PtrMemArray,"RE")
if @error Then Return SetError(2,0,0)
Return SetError(0,0,$RowsCount)
EndFunc

Func PDeletePtrMemArray(ByRef $PtrMemArray)
If Not IsDllStruct($PtrMemArray) Then Return SetError(1,0,False)
PFreePtrMemArray($PtrMemArray)
if @error Then Return SetError(2,0,False)
$PtrMemArray = ""
Return SetError(0,0,True)
EndFunc

Func PFreePtrMemArray($PtrMemArray)
If Not IsDllStruct($PtrMemArray) Then Return SetError(1,0,False)
Local $iRowsCount = PUBound($PtrMemArray),$Alloc
if @error Then Return SetError(2,0,False)
For $RowIndex = 0 To $iRowsCount - 1
$Alloc = DllStructGetData($PtrMemArray,"ARRAY",$RowIndex + 1)
free($Alloc)
Next
Return SetError(0,0,True)
EndFunc

Func PGetAt($PtrMemArray,$RowIndex,$Element = "",$ElementIndex = 0)
; $Element And $ElementIndex Only use If $DataType Is tagStruct
If Not IsDllStruct($PtrMemArray) Then Return SetError(1,0,"")
Local $iRowsCount = PUBound($PtrMemArray) , $Value = 0
If ($RowIndex < 0 Or $RowIndex > ($iRowsCount -1)) Then Return SetError(2,0,"")
Local $DataType = DllStructGetData($PtrMemArray,"TYPE")
if @error Then Return SetError(3,0,"")
Local $IsStruct = DllStructGetData($PtrMemArray,"ISSTRUCT")
if @error Then Return SetError(4,0,"")
Local $ElementPtr = PGetArrayElement($PtrMemArray,$RowIndex)
if @error Then Return SetError(5,0,"")
if ($IsStruct) Then
Switch $Element
Case ""
$Value = DllStructCreate($DataType,$ElementPtr)
if @error Then Return SetError(6,0,"")
Case Else
Switch $ElementIndex
Case 0
DllStructGetData(DllStructCreate($DataType,$ElementPtr),$Element,2)
if (Not(@error)) Then
$Value = DllStructGetPtr(DllStructCreate($DataType,$ElementPtr),$Element)
if @error Then Return SetError(7,0,"")
Else
$Value = DllStructGetData(DllStructCreate($DataType,$ElementPtr),$Element)
if @error Then Return SetError(8,0,"")
EndIf
Case Else
$Value = DllStructGetData(DllStructCreate($DataType,$ElementPtr),$Element,$ElementIndex)
if @error Then Return SetError(9,0,"")
EndSwitch
EndSwitch
Else
$Value = DllStructGetData(DllStructCreate($DataType,$ElementPtr),1)
if @error Then Return SetError(10,0,"")
EndIf
Return SetError(0,0,$Value)
EndFunc

Func PSetAt($PtrMemArray,$RowIndex,$vValue,$Element = "",$ElementIndex = 0)
; $Element And $ElementIndex Only use If $DataType Is tagStruct
; $vValue Must be Ptr Or Struct if $Element = "" And $DataType Is tagStruct
If Not IsDllStruct($PtrMemArray) Or Not IsMemDataType($vValue) Then Return SetError(1,0,False)
Local $iRowsCount = PUBound($PtrMemArray),$Value = 0
If ($RowIndex < 0 Or $RowIndex > ($iRowsCount -1)) Then Return SetError(2,0,False)
Local $SizeOfType = DllStructGetData($PtrMemArray,"SIZE")
if @error Then Return SetError(3,0,False)
Local $DataType = DllStructGetData($PtrMemArray,"TYPE")
if @error Then Return SetError(4,0,False)
Local $IsStruct = DllStructGetData($PtrMemArray,"ISSTRUCT")
if @error Then Return SetError(5,0,False)
Local $ElementPtr = PGetArrayElement($PtrMemArray,$RowIndex)
if @error Then Return SetError(6,0,False)
if ($IsStruct) Then
Switch $Element
Case ""
$Value = $vValue
if IsDllStruct($vValue) Then $Value = DllStructGetPtr($vValue)
if Not IsPtr($Value) Or $Value = Ptr(0) Then Return SetError(7,0,False)
_MemMoveMemory($Value,$ElementPtr,$SizeOfType)
Case Else
Switch $ElementIndex
Case 0
DllStructSetData(DllStructCreate($DataType,$ElementPtr),$Element,$vValue)
if @error Then Return SetError(8,0,False)
Case Else
DllStructSetData(DllStructCreate($DataType,$ElementPtr),$Element,$vValue,$ElementIndex)
if @error Then Return SetError(9,0,False)
EndSwitch
EndSwitch
Else
DllStructSetData(DllStructCreate($DataType,$ElementPtr),1,$vValue)
if @error Then Return SetError(10,0,False)
EndIf
Return SetError(0,0,True)
EndFunc

Func PGetArrayElement($PtrMemArray,$RowIndex)
If Not IsDllStruct($PtrMemArray) Then Return SetError(1,0,0)
Local $iRowsCount = PUBound($PtrMemArray)
If ($RowIndex < 0 Or $RowIndex > ($iRowsCount -1)) Then Return SetError(2,0,0)
Local $ElementPtr = DllStructGetData($PtrMemArray,"ARRAY",$RowIndex + 1)
if @error Then Return SetError(3,0,0)
Return SetError(0,0,$ElementPtr)
EndFunc

Func PGetArrayPtr($PtrMemArray,$MoveCount = 0)
If Not IsDllStruct($PtrMemArray) Then Return SetError(1,0,0)
Local $iRowsCount = PUBound($PtrMemArray)
If ($MoveCount < 0 Or $MoveCount > $iRowsCount) Then Return SetError(2,0,0)
Local $ArrayPtr = DllStructGetPtr($PtrMemArray,"ARRAY") + ($MoveCount * $PtrSize)
if @error Then Return SetError(3,0,0)
Return SetError(0,0,$ArrayPtr)
EndFunc

Func IstagStruct($DataType)
DllStructCreate($DataType)
if @error Then Return SetError(1,0,False)
Switch StringUpper($DataType)
Case "BYTE","BOOLEAN","CHAR","WCHAR","SHORT","USHORT","WORD","INT","LONG","BOOL","UINT","ULONG","DWORD","INT64","UINT64","PTR", _
"HWND","HANDLE","FLOAT","DOUBLE","INT_PTR","LONG_PTR","LRESULT","LPARAM","UINT_PTR","ULONG_PTR","DWORD_PTR","WPARAM"
Return SetError(0,0,False)
Case Else
Return SetError(0,0,True)
EndSwitch
EndFunc

Func IsMemDataType($Value)
if IsObj($Value) Or IsArray($Value) Then Return False
Return True
EndFunc

Func Alloc($iSize)
$hMemory = _MemGlobalAlloc($iSize,$GHND)
if Not($hMemory) Then Return SetError(1,0,0)
$hLock = _MemGlobalLock($hMemory)
if Not($hLock) Then Return SetError(2,0,0)
Return SetError(0,0,$hLock)
EndFunc

Func GlobalHandle($hLock)
$HGLOBAL = DllCall("Kernel32.dll","ptr","GlobalHandle","ptr",$hLock)
if @error Or $HGLOBAL[0] = 0 Then Return SetError(1,0,0)
Return $HGLOBAL[0]
EndFunc

Func free($hLock)
$hMem = GlobalHandle($hLock)
if @error Then Return SetError(1,0,False)
$Return = _MemGlobalFree($hMem)
if ($Return <> 0) Then Return SetError(2,0,False)
Return SetError(0,0,True)
EndFunc

Func StrucMemArrayGet_DataArray($StrucMemArray)
if Not IsDllStruct($StrucMemArray) Then Return SetError(1,0,False)
Local $RowsCount = SUBound($StrucMemArray)
if @error Then Return SetError(2,0,False)
Local $DataType = DllStructGetData($StrucMemArray,"TYPE")
if @error Then Return SetError(3,0,False)
$DataType = StringStripWS($DataType,3)
if (StringRight($DataType,1) == ";") Then $DataType = StringTrimRight($DataType,1)
$StringSpA = StringSplit($DataType,";")
Local $DataArray[($RowsCount + 1)][($StringSpA[0] + 1)]
$DataArray[0][0] = String("Rows = " & $RowsCount & " | Elements = " & $StringSpA[0])
For $i = 1 To $RowsCount
$DataArray[$i][0] = String("MemArray RowIndex " & ($i - 1))
Local $MovePos = 0
For $j = 1 To $StringSpA[0]
Local $Element = "" , $ElementName = "" , $Value = ""
$Element = space($StringSpA[$j])
$StringSpB = StringSplit($Element," ")
if StringInStr($StringSpB[1],"[") Then $StringSpB = StringSplit($Element,"[")
For $n = 2 To $StringSpB[0]
$ElementName &= $StringSpB[$n]
Next
Switch StringLen($ElementName)
Case 0
$ElementName = String("- Union -")
Case Else
if (Not StringInStr($ElementName,"[")) Then
$ElementName = StringReplace($ElementName,"]","")
if (StringIsInt($ElementName)) Then $ElementName = String("- Union[" & $ElementName & "] -")
EndIf
EndSwitch
$DataArray[0][$j] = $ElementName
$DataArray[$i][$j] = SGetAt($StrucMemArray,($i - 1),$j)
$MovePos += DllStructGetSize(DllStructCreate($Element))
Next
Next
Return SetError(0,0,$DataArray)
EndFunc

Func PtrMemArrayGet_DataArray($PtrMemArray)
if Not IsDllStruct($PtrMemArray) Then Return SetError(1,0,False)
Local $RowsCount = PUBound($PtrMemArray)
if @error Then Return SetError(2,0,False)
Local $DataType = DllStructGetData($PtrMemArray,"TYPE")
if @error Then Return SetError(3,0,False)
$DataType = StringStripWS($DataType,3)
if (StringRight($DataType,1) == ";") Then $DataType = StringTrimRight($DataType,1)
$StringSpA = StringSplit($DataType,";")
Local $DataArray[($RowsCount + 1)][($StringSpA[0] + 1)]
$DataArray[0][0] = String("Rows = " & $RowsCount & " | Elements = " & $StringSpA[0])
For $i = 1 To $RowsCount
$DataArray[$i][0] = String("MemArray RowIndex " & ($i - 1))
Local $MovePos = 0
For $j = 1 To $StringSpA[0]
Local $Element = "" , $ElementName = "" , $Value = ""
$Element = space(space($StringSpA[$j]))
$StringSpB = StringSplit($Element," ")
if StringInStr($StringSpB[1],"[") Then $StringSpB = StringSplit($Element,"[")
For $n = 2 To $StringSpB[0]
$ElementName &= $StringSpB[$n]
Next
Switch StringLen($ElementName)
Case 0
$ElementName = String("- Union -")
Case Else
if (Not StringInStr($ElementName,"[")) Then
$ElementName = StringReplace($ElementName,"]","")
if (StringIsInt($ElementName)) Then $ElementName = String("- Union[" & $ElementName & "] -")
EndIf
EndSwitch
$DataArray[0][$j] = $ElementName
$DataArray[$i][$j] = PGetAt($PtrMemArray,($i - 1),$j)
$MovePos += DllStructGetSize(DllStructCreate($Element))
Next
Next
Return SetError(0,0,$DataArray)
EndFunc

Func space($Text)
Local $OutText = ""
$Text = StringStripWS($Text,3)
For $i = 1 To StringLen($Text)
$Char = StringMid($Text,$i,1)
if (Not StringIsSpace($Char)) Then
$OutText  &= $Char
Else
$OutText &= " "
While 1
$i += 1
$Char = StringMid($Text,$i,1)
if (Not StringIsSpace($Char)) Then
$i -= 1
ExitLoop
EndIf
WEnd
EndIf
Next
Return $OutText
EndFunc

Func CreateDispTypeInfo($Struidata)
$HRESULT = DllCall("OleAut32.dll","long","CreateDispTypeInfo","struct*",$Struidata,"DWORD",0,"ptr*",0)
if @error Or $HRESULT[0] <> 0 Then Return SetError(1,0,0)
$pptinfo = $HRESULT[3]
Return $pptinfo
EndFunc

Func DispGetIDsOfNames($ptinfo,$rgszNames)
$HRESULT = DllCall("OleAut32.dll","long","DispGetIDsOfNames","ptr",$ptinfo,"ptr",$rgszNames,"UINT",1,"long*",0)
if @error Or $HRESULT[0] <> 0 Then Return SetError(1,0,0)
$rgdispid = $HRESULT[4]
Return $rgdispid
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0