Jump to content

Recommended Posts

Posted

I don't know any other language except AutoIt, but I can still say that the AutoIt loop is slow.
So, why no array pointer in Autoit?
You can merge two SafeArrays (1D / 2D) using RtlMoveMemory,
which will be much faster compared to AutoIt’s _ArrayAdd.

Can anyone convert AutoIt’s _ArrayDelete to C and then to machine code?

Posted (edited)
36 minutes ago, jugador said:

I don't know any other language except AutoIt, ... Can anyone convert AutoIt’s _ArrayDelete to C and then to machine code?

AutoIt is great but, there are things that AutoIt was never meant for. Like a fast ..anything.

@jugador, do go and learn something else. That does not mean that you'll never code scripts again. It'll mean that you'll have more tools at your disposal :) 

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

You may use structs and define in structs arrays. With struct arrays you can use the winapi memory functions.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

@UEZ 

you can create one dimensional or two dimensional safearray.

Local $1D_SafeArray = DllStructCreate( $tagSAFEARRAYBOUND)
Local $2D_SafeArray = DllStructCreate( $tagSAFEARRAYBOUND  & $tagSAFEARRAYBOUND)

Even though AutoIt does not provide array pointers, you can still get an array pointer by converting it to a SafeArray.
You don't need a loop to convert an array to a SafeArray and back to Array if you follow @LarsJ post.

Edited by jugador
Posted

@argumentum

It’s not easy to learn something new.

It sound like when you say, “go learn something else” — AutoIt was primarily designed for automation tasks like mouse clicking, and nothing more. 
Maybe @trancexx, @ProgAndy, @LarsJ, @Ward, and the rest who tried to take AutoIt beyond simple mouse clicks have wasted their time.

So, Is there any real value in using AutoIt for someone who already knows C, C++, Python......?

Posted (edited)

Something like that:

1D:

;coded by UEZ
#include <WinAPIDiag.au3>
#include <Memory.au3>

Global $iElements = 2^5
ConsoleWrite("Number of entries: " & $iElements & @CRLF)

Global $tArray = DllStructCreate("uint a[" & $iElements & "]")
Global $pArray = DllStructGetPtr($tArray)

For $i = 1 To $iElements
    $tArray.a(($i)) = $i
Next
Global $iPos = Int($iElements * 0.667)
ConsoleWrite("Insert to position " & $iPos & @CRLF)

InsertValue(123456789, $iPos, $tArray, $pArray, "uint")
_WinAPI_DisplayStruct($tArray, "uint a[" & $iElements + 1 & "]")

Func InsertValue($value, $iPos, ByRef $tArray, ByRef $pArray, $type)
    If Not IsDllStruct($tArray) Then Return SetError(1, 0, 0)
    Local $iUB, $iBytes
    Switch $type
        Case "wchar", "short", "ushort", "word"
            $iBytes = 2
            $iUB = DllStructGetSize($tArray) / $iBytes
        Case "float", "int", "long", "bool", "uint", "ulong"
            $iBytes = 4
            $iUB = DllStructGetSize($tArray) / $iBytes
        Case "int64", "uint64", "double"
            $iBytes = 8
            $iUB = DllStructGetSize($tArray) / $iBytes
        Case Else
            Return SetError(2, 0, 0)
    EndSwitch
    If $iPos < 1 Or $iPos > $iUB Then SetError(3, 0, 0)
    $iUB += 1
    Local $tArray_new = DllStructCreate($type & " a[" & $iUB & "]")
    $pArray = DllStructGetPtr($tArray_new)
    _MemMoveMemory(DllStructGetPtr($tArray), $pArray, ($iPos - 1) * $iBytes)
    $tArray_new.a(($iPos)) = $value
    _MemMoveMemory(DllStructGetPtr($tArray) + ($iPos - 1) * $iBytes, $pArray + $iPos * $iBytes , ($iUB - $iPos) * $iBytes)
    $tArray = $tArray_new
    Return 1
EndFunc

 

2D:

#include <WinAPIDiag.au3>
#include <Memory.au3>

Global Const $iWidth = 5, $iHeight = 4
Global Const $iTotal = $iWidth * $iHeight

Global $t2DArray = DllStructCreate("uint a[" & $iTotal & "]") ;2D array
Global $pArray = DllStructGetPtr($t2DArray)

Global $x, $y, $t, $index                               ;2D
For $y = 0 To $iHeight - 1                              ;0  1   2   3   4
    $t = $y * $iWidth                                   ;10 11  12  13  14
    For $x = 0 To $iWidth - 1                           ;20 21  22  23  24
        $index = $t + $x                                ;30 31  32  33  34
        $t2DArray.a(($index + 1)) = $y & $x             ;
    Next                                                ;1D -> 0 1 2 3 4 10 11 12 13 14 20 21 22 23 24 30 31 32 33 34
Next

Print2DArray($t2DArray, $iWidth, $iHeight)
InsertValue2D(99, 0, 0, $t2DArray, $pArray, $iWidth, $iHeight, "uint")
ConsoleWrite(@CRLF & "Result (add 99 at 0, 0):" & @CRLF)

Print2DArray($t2DArray, $iWidth, $iHeight + 1)

DeleteValue2D(2, 2, $t2DArray, $pArray, $iWidth, $iHeight + 1, "uint")

ConsoleWrite(@CRLF & "Result (del 2, 2 -> 21):" & @CRLF)
Print2DArray($t2DArray, $iWidth, $iHeight)

Func InsertValue2D($value, $xPos, $yPos, ByRef $tStruct, ByRef $pArray, $cols, $rows, $type)
    Local $oldElements = $cols * $rows
    Local $newRows = $rows + 1
    Local $newElements = $cols * $newRows
    Local $elementSize

    Switch $type
        Case "ushort", "short", "word"
            $elementSize = 2
        Case "uint", "int", "float"
            $elementSize = 4
        Case "double", "int64", "uint64"
            $elementSize = 8
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch

    Local $tNew = DllStructCreate($type & " a[" & $newElements & "]")
    Local $pNew = DllStructGetPtr($tNew)

    Local $insertIndex = $yPos * $cols + $xPos
    If $insertIndex < 0 Or $insertIndex > $oldElements Then Return SetError(1, 0, 0)

    _MemMoveMemory($pArray, $pNew, $insertIndex * $elementSize)

    $tNew.a($insertIndex + 1) = $value

    Local $bytesAfter = ($oldElements - $insertIndex) * $elementSize
    _MemMoveMemory($pArray + ($insertIndex * $elementSize), $pNew + (($insertIndex + 1) * $elementSize), $bytesAfter)

    $tStruct = $tNew
    $pArray = $pNew

    Return 1
EndFunc

Func DeleteValue2D($xPos, $yPos, ByRef $tStruct, ByRef $pArray, $cols, $rows, $type)
    Local $oldElements = $cols * $rows
    If $rows < 2 Then Return SetError(1, 0, 0)

    Local $newElements = $oldElements - 1
    Local $elementSize

    Switch $type
        Case "ushort", "short", "word"
            $elementSize = 2
        Case "uint", "int", "float"
            $elementSize = 4
        Case "double", "int64", "uint64"
            $elementSize = 8
        Case Else
            Return SetError(2, 0, 0)
    EndSwitch

    Local $deleteIndex = $yPos * $cols + $xPos
    If $deleteIndex < 0 Or $deleteIndex >= $oldElements Then Return SetError(3, 0, 0)

    Local $tNew = DllStructCreate($type & " a[" & $newElements & "]")
    Local $pNew = DllStructGetPtr($tNew)

    _MemMoveMemory($pArray, $pNew, $deleteIndex * $elementSize)

    Local $bytesAfter = ($oldElements - $deleteIndex - 1) * $elementSize
    _MemMoveMemory($pArray + (($deleteIndex + 1) * $elementSize), $pNew + ($deleteIndex * $elementSize), $bytesAfter)

    $tStruct = $tNew
    $pArray = $pNew

    Return 1
EndFunc

Func Print2DArray($t2DArray, $cols, $rows)
    Local $x, $y, $index
    For $y = 0 To $rows - 1
        For $x = 0 To $cols - 1
            $index = $y * $iWidth + $x
            ConsoleWrite($t2DArray.a($index + 1) & @TAB)
        Next
        ConsoleWrite(@CRLF)
    Next
EndFunc

 

Edited by UEZ
Bug fixed.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
3 hours ago, jugador said:

So, Is there any real value in using AutoIt for someone who already knows C, C++, Python......?

I can run AutoIt without any dependencies anywhere. It just runs. Nimble too. A GUI with AutoIt is easy.
If I had to do all the things I do in C++ it'd be slower and unforgiving for me. Python is here to stay, and I don't like Python.

I'll have to go through the advise I gave you myself for all the AI stuff that is floating around and my brain is never been all that great to start with, and adding aging to the pot don't make it easier either. Yet the advise is the same.

I feel you. I really do. But "it is what it is", for you, me, or anyone.

17 hours ago, jugador said:

Can anyone convert AutoIt’s _ArrayDelete to C and then to machine code?

I guess you'd do it in ASM and use the FASM.
I'd use SQLite and call it a day. Not that I know SQL all that much, but am sure that whatever you're gonna use that big array for, could be done with SQLite, I think.

17 hours ago, jugador said:

I don't know any other language except AutoIt

Same here.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
4 hours ago, jugador said:

Maybe @trancexx, @ProgAndy, @LarsJ, @Ward, and the rest who tried to take AutoIt beyond simple mouse clicks have wasted their time.

Each of these users have their unique stories with their love for AutoIt ( and am not exaggerating when I say "their love" for AutoIt ). Just can't put them all in the same pot.

There is also the forum life and the ungratefulness and aggravation they go though, that understandingly push them away from the forum.
So because they don't devote attention to the forum, don't mean that they never used AutoIt again. It just mean that they don't frequent the forum.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

@UEZ

I know how to merge / delete / insert element in DllStruct and safearray using RtlMoveMemory.
but using RtlMoveMemory like this with big size 2D Array cumbersome process.
that's why looking for machine code.

__Example_A( ) ;~ delete element
Func __Example_A( )
    Local $n = 20
    Local $tIntegers = DllStructCreate( "int[" & $n & "]" )
    Local $pIntegers = DllStructGetPtr( $tIntegers )

    For $i = 1 To $n
        DllStructSetData($tIntegers, 1, $i, $i)
    Next

    For $i = 1 To $n
        ConsoleWrite(": " & DllStructGetData($tIntegers, 1, $i) & @CRLF)
    Next

    ConsoleWrite(@CRLF & " < after delete of row from 6 to 16 > " & @CRLF)
    ;~~ Delet Row from 6 to 16
    Local $no_Element_toRemove = (16 - 6) + 1
    Local $t_New = DllStructCreate( "int[" & $n - $no_Element_toRemove & "]" )
    Local $p_New = DllStructGetPtr( $t_New )

    DllCall("kernel32.dll", "none", "RtlMoveMemory", "ptr", $p_New, "ptr", $pIntegers, "dword", 20 )
    DllCall("kernel32.dll", "none", "RtlMoveMemory", "ptr", $p_New + 20, "ptr", $pIntegers + 64, "dword", 16 )

    For $i = 1 To $n - $no_Element_toRemove
        ConsoleWrite(": " & DllStructGetData($t_New, 1, $i) & @CRLF)
    Next
EndFunc

 

Edited by jugador
Posted (edited)

Just made a quick test for 2D struct array:

;Code by UEZ
#AutoIt3Wrapper_UseX64=y
#include <WinAPIDiag.au3>
#include <Memory.au3>

Global Const $iWidth = 1000, $iHeight = 4000
Global Const $iTotal = $iWidth * $iHeight
ConsoleWrite("Total: " & $iTotal & @CRLF)

Global $t2DArray = DllStructCreate("uint a[" & $iTotal & "]") ;2D array
Global $pArray = DllStructGetPtr($t2DArray)

Global $x, $y, $t, $index                               ;2D
For $y = 0 To $iHeight - 1                              ;0  1   2   3   4
    $t = $y * $iWidth                                   ;10 11  12  13  14
    For $x = 0 To $iWidth - 1                           ;20 21  22  23  24
        $index = $t + $x                                ;30 31  32  33  34
        $t2DArray.a(($index + 1)) = $y & $x             ;
    Next                                                ;1D -> 0 1 2 3 4 10 11 12 13 14 20 21 22 23 24 30 31 32 33 34
Next

Global $fTimer = TimerInit()
;~ Print2DArray($t2DArray, $iWidth, $iHeight)
InsertValue2D(99, 0, 0, $t2DArray, $pArray, $iWidth, $iHeight, "uint")
;~ ConsoleWrite(@CRLF & "Result (add 99 at 0, 0):" & @CRLF)
ConsoleWrite(TimerDiff($fTimer) & @CRLF)

;~ Print2DArray($t2DArray, $iWidth, $iHeight + 1)

DeleteValue2D(2, 2, $t2DArray, $pArray, $iWidth, $iHeight + 1, "uint")
ConsoleWrite(TimerDiff($fTimer) & @CRLF)

;~ ConsoleWrite(@CRLF & "Result (del 2, 2 -> 21):" & @CRLF)
;~ Print2DArray($t2DArray, $iWidth, $iHeight)

Func InsertValue2D($value, $xPos, $yPos, ByRef $tStruct, ByRef $pArray, $cols, $rows, $type)
    Local $oldElements = $cols * $rows
    Local $newRows = $rows + 1
    Local $newElements = $cols * $newRows
    Local $elementSize

    Switch $type
        Case "ushort", "short", "word"
            $elementSize = 2
        Case "uint", "int", "float"
            $elementSize = 4
        Case "double", "int64", "uint64"
            $elementSize = 8
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch

    Local $tNew = DllStructCreate($type & " a[" & $newElements & "]")
    Local $pNew = DllStructGetPtr($tNew)

    Local $insertIndex = $yPos * $cols + $xPos
    If $insertIndex < 0 Or $insertIndex > $oldElements Then Return SetError(1, 0, 0)

    _MemMoveMemory($pArray, $pNew, $insertIndex * $elementSize)

    $tNew.a($insertIndex + 1) = $value

    Local $bytesAfter = ($oldElements - $insertIndex) * $elementSize
    _MemMoveMemory($pArray + ($insertIndex * $elementSize), $pNew + (($insertIndex + 1) * $elementSize), $bytesAfter)

    $tStruct = $tNew
    $pArray = $pNew

    Return 1
EndFunc

Func DeleteValue2D($xPos, $yPos, ByRef $tStruct, ByRef $pArray, $cols, $rows, $type)
    Local $oldElements = $cols * $rows
    If $rows < 2 Then Return SetError(1, 0, 0)

    Local $newElements = $oldElements - 1
    Local $elementSize

    Switch $type
        Case "ushort", "short", "word"
            $elementSize = 2
        Case "uint", "int", "float"
            $elementSize = 4
        Case "double", "int64", "uint64"
            $elementSize = 8
        Case Else
            Return SetError(2, 0, 0)
    EndSwitch

    Local $deleteIndex = $yPos * $cols + $xPos
    If $deleteIndex < 0 Or $deleteIndex >= $oldElements Then Return SetError(3, 0, 0)

    Local $tNew = DllStructCreate($type & " a[" & $newElements & "]")
    Local $pNew = DllStructGetPtr($tNew)

    _MemMoveMemory($pArray, $pNew, $deleteIndex * $elementSize)

    Local $bytesAfter = ($oldElements - $deleteIndex - 1) * $elementSize
    _MemMoveMemory($pArray + (($deleteIndex + 1) * $elementSize), $pNew + ($deleteIndex * $elementSize), $bytesAfter)

    $tStruct = $tNew
    $pArray = $pNew

    Return 1
EndFunc

Func Print2DArray($t2DArray, $cols, $rows)
    Local $x, $y, $index
    For $y = 0 To $rows - 1
        For $x = 0 To $cols - 1
            $index = $y * $iWidth + $x
            ConsoleWrite($t2DArray.a($index + 1) & @TAB)
        Next
        ConsoleWrite(@CRLF)
    Next
EndFunc

It took 13 seconds to execute insert and delete operation for one element each for an array with 4.000.000 elements.

 

I don't know how long it would take using ASM...

I'm pretty rusty when it comes to ASM. ¯\_(ツ)_/¯

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

@UEZ and other members

Can I get little help :D
both the C code is returning SafeArray pointer if we compile it as dll and run it from Autoit?

 

#include <windows.h>
#include <oleauto.h>

// Function to create a SafeArray of 10 VT_VARIANT elements
SAFEARRAY* CreateSafeArray(void) {
    // Define SafeArray bounds (1D array with 10 elements)
    SAFEARRAYBOUND bounds = { 10, 0 }; // 10 elements, lower bound 0
    
    // Create SafeArray of VARIANT type
    SAFEARRAY* sa = SafeArrayCreate(VT_VARIANT, 1, &bounds);
    if (!sa) return NULL;

    // Access SafeArray data
    VARIANT* data;
    HRESULT hr = SafeArrayAccessData(sa, (void**)&data);
    if (FAILED(hr)) {
        SafeArrayDestroy(sa);
        return NULL;
    }

    // Populate the SafeArray with VT_I4 values (0 to 9)
    for (int i = 0; i < 10; i++) {
        VariantInit(&data[i]);
        data[i].vt = VT_I4;
        data[i].lVal = i + 1;
    }

    // Release SafeArray data
    SafeArrayUnaccessData(sa);

    return sa;
}

 

#include <windows.h>
#include <oleauto.h>

// Function to create a SafeArray of 10 VT_VARIANT elements
void CreateSafeArray(void* ptr) {
    // Validate output parameter
    if (!ptr) return;
    SAFEARRAY** out = (SAFEARRAY**)ptr;
    *out = NULL; // Initialize output to NULL

    // Define SafeArray bounds (1D array with 10 elements)
    SAFEARRAYBOUND bounds = { 10, 0 }; // 10 elements, lower bound 0
    
    // Create SafeArray of VARIANT type
    SAFEARRAY* sa = SafeArrayCreate(VT_VARIANT, 1, &bounds);
    if (!sa) return;

    // Access SafeArray data
    VARIANT* data;
    HRESULT hr = SafeArrayAccessData(sa, (void**)&data);
    if (FAILED(hr)) {
        SafeArrayDestroy(sa);
        return;
    }

    // Populate the SafeArray with VT_I4 values (0 to 9)
    for (LONG i = 0; i < 10; i++) {
        VariantInit(&data[i]);
        data[i].vt = VT_I4;
        data[i].lVal = i + 1; 
    }

    // Release SafeArray data
    SafeArrayUnaccessData(sa);

    // Return the SafeArray through the output parameter
    *out = sa;
}

 

to check if it's correct SafeArray pointer

Global Const $tagSAFEARRAYBOUND = _
    "ulong  cElements;"  & _ ; The number of elements in the dimension.
    "long   lLbound;"        ; The lower bound of the dimension.

Global Const $tagSAFEARRAY = _
    "ushort cDims;"      & _ ; The number of dimensions.
    "ushort fFeatures;"  & _ ; Flags, see below.
    "ulong  cbElements;" & _ ; The size of an array element.
    "ulong  cLocks;"     & _ ; The number of times the array has been locked without a corresponding unlock.
    "ptr    pvData;"     & _ ; The data.
    $tagSAFEARRAYBOUND       ; One $tagSAFEARRAYBOUND for each dimension.


__Example_A( )
Func __Example_A( )
    Local $aResult = DllCall(........)
    Local $tSafeArray = DllStructCreate( $tagSAFEARRAY, $aResult[0] )
    ConsoleWrite(DllStructGetData( $tSAFEARRAY, "cDims" ) & @Crlf)                        
    ConsoleWrite(DllStructGetData( $tSAFEARRAY, "fFeatures" ) & @Crlf)    
    ConsoleWrite(DllStructGetData( $tSAFEARRAY, "cbElements" ) & @Crlf)                
    ConsoleWrite(DllStructGetData( $tSAFEARRAY, "pvData" ) & @Crlf)
    ConsoleWrite(DllStructGetData( $tSAFEARRAY, "cElements" ) & @Crlf)    
    ConsoleWrite(DllStructGetData( $tSAFEARRAY, "lLbound" ) & @Crlf)
EndFunc

 

Edited by jugador
Posted (edited)

I've an experience with safe arrays.

Converted from the C code above:

Global Const $VT_I4 = 3
Global Const $VT_VARIANT = 12

Global Const $tagSAFEARRAYBOUND = "ulong cElements; long lLbound;"
Global Const $tagVARIANT = "ushort vt; ushort r1; ushort r2; ushort r3; int lVal; ptr dummy"
Global Const $tagSAFEARRAY = _
                            "ushort cDims;"      & _ ; The number of dimensions.
                            "ushort fFeatures;"  & _ ; Flags, see below.
                            "ulong  cbElements;" & _ ; The size of an array element.
                            "ulong  cLocks;"     & _ ; The number of times the array has been locked without a corresponding unlock.
                            "ptr    pvData;"     & _ ; The data.
                            $tagSAFEARRAYBOUND       ; One $tagSAFEARRAYBOUND for each dimension.

; Create a SafeArray with 10 VT_VARIANT elements
Func CreateSafeArray()
    ; Prepare SAFEARRAYBOUND structure
    Local $bound = DllStructCreate($tagSAFEARRAYBOUND)
    $bound.cElements = 10
    $bound.lLbound = 0

    ; Call SafeArrayCreate
    Local $aRet = DllCall("oleaut32.dll", "ptr", "SafeArrayCreate", "ushort", $VT_VARIANT, "uint", 1, "struct*", $bound)

    If @error Or IsPtr($aRet[0]) = 0 Then
        ConsoleWrite("SafeArrayCreate failed" & @CRLF)
        Return SetError(1, 0, 0)
    EndIf

    Local $pArray = $aRet[0]

    ; Lock/Access SafeArray
    Local $pData
    $aRet = DllCall("oleaut32.dll", "long", "SafeArrayAccessData", "ptr", $pArray, "ptr*", 0)

    If @error Or $aRet[0] <> 0 Then
        ConsoleWrite("SafeArrayAccessData failed" & @CRLF)
        DllCall("oleaut32.dll", "long", "SafeArrayDestroy", "ptr", $pArray)
        Return SetError(2, 0, 0)
    EndIf

    $pData = $aRet[2]

    ; Fill 10 VARIANTs with integer values
    For $i = 0 To 9
        Local $variant = DllStructCreate($tagVARIANT, $pData + ($i * 16)) ;each variant has 16 bytes
        $variant.vt = $VT_I4
        $variant.lVal = $i + 1
    Next

    ; Unaccess array
    DllCall("oleaut32.dll", "long", "SafeArrayUnaccessData", "ptr", $pArray)

    Return $pArray ; pointer to the SafeArray
EndFunc

Global $pSafeArray = CreateSafeArray()

Local $tSafeArray = DllStructCreate( $tagSAFEARRAY, $pSafeArray)
ConsoleWrite("cDims: " & DllStructGetData( $tSAFEARRAY, "cDims" ) & @Crlf)
ConsoleWrite("fFeatures: " & DllStructGetData( $tSAFEARRAY, "fFeatures" ) & @Crlf)
ConsoleWrite("cbElements: " & DllStructGetData( $tSAFEARRAY, "cbElements" ) & @Crlf)
ConsoleWrite("pvData: " & DllStructGetData( $tSAFEARRAY, "pvData" ) & @Crlf)
ConsoleWrite("cElements: " & DllStructGetData( $tSAFEARRAY, "cElements" ) & @Crlf)
ConsoleWrite("lLbound: " & DllStructGetData( $tSAFEARRAY, "lLbound" ) & @Crlf)

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

What I am taking is not how to create a SafeArray in AutoIt but to pass SafeArray pointer to C or from C :P
Finally managed something.....

#include "SafeArray.au3"
#include "Variant.au3"

__Example_A( )

Func __Example_A( )
    Local $no = 10
    Local $tsaBound = DllStructCreate( $tagSAFEARRAYBOUND )
    DllStructSetData( $tsaBound, "cElements", $no )
    DllStructSetData( $tsaBound, "lLbound", 0 )
    Local $psa = SafeArrayCreate( $VT_R8  , 1, $tsaBound )

    Local $psaData
    SafeArrayAccessData( $psa, $psaData )
    
    Local $Code = Binary('0x558BEC8B4D088B550CB80000000089024083020183C208E2F55DC20800')
    Local $iSize = BinaryLen($Code)
    Local $tCode = DllStructCreate('byte Code[' & $iSize & ']')
    DllStructSetData($tCode, 'Code', $Code)
    Local $aCall = DllCallAddress( "int", DllStructGetPtr($tCode), "int", $no, "ptr", $psaData )
    
    SafeArrayUnaccessData( $psa )
    
    Local $tStruct
    Local $tSafeArray = DllStructCreate( $tagSAFEARRAY, $psa )
    For $i = 0 To $no - 1
        $tStruct = DllStructCreate('int', DllStructGetData( $tSAFEARRAY, "pvData" ) + ( $i * 8))
        ConsoleWrite($i & ': ' & DllStructGetData($tStruct, 1) & @CRLF)
    Next
    SafeArrayDestroy($psa)
EndFunc

 

Edited by jugador

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...