Jump to content

Alternative to DllStructGetData()


Recommended Posts

Hello everybody!

I created this thread for people like me, may have clarification on what was mentioned in this thread:

I asked a question here , but not to remove focus from the topic I decided to open this one!


I did several speed tests using this method: '?do=embed' frameborder='0' data-embedContent>>

And indeed in this way:

$dBytes = $tBuffer.array
It is up to 40% faster than this:

$dBytes = DllStructGetData($tBuffer, 'array')
Who could answer what are the advantages and disadvantages of using this method, if support for this format will continue in future versions, the consequences of use and etc..

JS

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

You can access arrays this way:

$tStruct = DllStructCreate("uint X[10];")

For $i = 1 To 10
    $tStruct.X(($i)) = $i
Next

For $i = 1 To 10
    $tStruct.X(($i)) *= 2
Next

For $i = 1 To 10
    ConsoleWrite("> " & $tStruct.X(($i)) & @CRLF)
Next

Here is a benchmarkscript i wrote some time ago: http://www.autoit.de/index.php?page=Thread&postID=358070#post358070

 

E

Link to comment
Share on other sites

@eukalyptus

Good friend, I did not know how to access the index in this way!

My results with your code:

! write[string] 774.94 zeit 1.19 x langsamer

- write[index] 686.91 zeit 1.06 x langsamer

> write[object] 649.25 zeit 1.00 x langsamer

! read[string] 734.50 zeit 1.66 x langsamer

- read[index] 643.64 zeit 1.46 x langsamer

> read[object] 441.37 zeit 1.00 x langsamer

! add[string] 1519.86 zeit 1.69 x langsamer

- add[index] 1322.80 zeit 1.47 x langsamer

> add[object] 897.54 zeit 1.00 x langsamer

- write array[string] 961.68 zeit 1.11 x langsamer

> write array[index] 868.35 zeit 1.00 x langsamer

! write array[object] 1325.64 zeit 1.53 x langsamer

- read array[string] 937.50 zeit 1.10 x langsamer

> read array[index] 850.55 zeit 1.00 x langsamer

! read array[object] 1109.98 zeit 1.31 x langsamer

Just as "array [object]" is that was a bit slower than the conventional way.

JS

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

eukalyptus,

How did you learn/notice/guess that this index syntax would work in AutoIt? I don't recall seeing it mentionned anywhere.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

@jchd

Take a test and prove it!


@eukalyptus

Excellent example in your code:

Local $tPoly = DllStructCreate("float Pnt[6];")
    $tPoly.Pnt(1) = $fCX
    $tPoly.Pnt(2) = $fCY
JS

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

eukalyptus,

How did you learn/notice/guess that this index syntax would work in AutoIt? I don't recall seeing it mentionned anywhere.

 

This "feature" was discovered by Minx and Mars (autoit.de).

I like using structs as objects!

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

HotKeySet("{ESC}", "_Exit")

_GDIPlus_Startup()

Global $tWin = _Win_Create(0, 0, @DesktopWidth, @DesktopHeight)

Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00)



Global $fX, $fY, $fW, $fH
While Sleep(500)

    _GDIPlus_GraphicsClear($tWin.GFX, 0)

    For $i = 1 To 10
        _GDIPlus_BrushSetSolidColor($hBrush, BitOR(0x80000000, BitShift(Random(0, 0xFF, 1), -16), BitShift(Random(0, 0xFF, 1), -8), Random(0, 0xFF, 1)))
        $fW = Random(50, 300)
        $fH = Random(50, 300)
        $fX = Random(0, @DesktopWidth - $fW)
        $fY = Random(0, @DesktopHeight - $fH)

        _GDIPlus_GraphicsFillEllipse($tWin.Gfx, $fX, $fY, $fW, $fH, $hBrush)
    Next

    _Win_Draw($tWin)
WEnd



Func _Win_Create($iX, $iY, $iW, $iH)
    Local $tWin = DllStructCreate("int X; int Y; int W; int H; hwnd Gui; hwnd DC; handle GFX; handle BMP; hwnd CDC; hwnd OBJ; int Src[2]; byte Blend[4];")

    $tWin.Blend(3) = 0xFF
    $tWin.Blend(4) = 1
    $tWin.X = $iX
    $tWin.Y = $iY
    $tWin.W = $iW
    $tWin.H = $iH

    $tWin.Gui = GUICreate("", $iW, $iH, $iX, $iY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

    $tWin.DC = _WinAPI_GetDC($tWin.Gui)

    Local $hBMP = _WinAPI_CreateCompatibleBitmap($tWin.DC, $iW, $iH)
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
    _WinAPI_DeleteObject($hBMP)

    $tWin.BMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)

    $tWin.CDC = _WinAPI_CreateCompatibleDC($tWin.DC)
    $tWin.OBJ = _WinAPI_SelectObject($tWin.CDC, $tWin.BMP)

    $tWin.GFX = _GDIPlus_GraphicsCreateFromHDC($tWin.CDC)

    GUISetState(@SW_SHOWNOACTIVATE, $tWin.Gui)

    Return $tWin
EndFunc   ;==>_Win_Create


Func _Win_Dispose(ByRef $tWin)
    If Not IsDllStruct($tWin) Then Return

    _GDIPlus_GraphicsDispose($tWin.GFX)
    _WinAPI_SelectObject($tWin.CDC, $tWin.OBJ)
    _WinAPI_DeleteObject($tWin.BMP)
    _WinAPI_DeleteDC($tWin.CDC)
    _WinAPI_ReleaseDC($tWin.Gui, $tWin.DC)
    GUIDelete($tWin.Gui)
    $tWin = 0
EndFunc   ;==>_Win_Dispose


Func _Win_Draw(ByRef $tWin)
    If Not IsDllStruct($tWin) Then Return
    _WinAPI_UpdateLayeredWindow($tWin.Gui, $tWin.DC, DllStructGetPtr($tWin, "X"), DllStructGetPtr($tWin, "W"), $tWin.CDC, DllStructGetPtr($tWin, "Src"), 0, DllStructGetPtr($tWin, "Blend"), 2)
EndFunc   ;==>_Win_Draw


Func _Exit()
    _GDIPlus_BrushDispose($hBrush)
    _Win_Dispose($tWin)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

In this example I have one struct for all things I need to draw and call _WinAPI_UpdateLayeredWindow

I can add, remove or change the order of the elements without changing the rest of the script.

And the code is easy to read.

Link to comment
Share on other sites

What is wrong with using an array and enumeration constants? You are abusing a feature that is designed for use with Dlls.

Global Enum $STRUCT_GUI, $STRUCT_X, $STRUCT_Y, $STRUCT_MAX

Example()

Func Example()
    Local $tWin[$STRUCT_MAX]
    $tWin[$STRUCT_GUI] = GuiCreate( ...
    $tWin[$STRUCT_X] = 100
    $tWin[$STRUCT_Y] = 140
EndFunc

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I would say it is "only" a new style of coding with a touch of OO language fealing - not more not less. And it makes no sense to ask why not using arrays or something else.

This makes the language "rich" to have many possibilities.

Br,

UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Don't get me wrong, I like the object orientated programming paradigm (I use C#) but the inner workings of DllStruct() aren't geared for this design approach. Don't just take my word for it, Valik, trancexx and Jon have all agreed in the past.

Plus, look at my Stack(), Queue(), Binary() or StopWatch() UDFs. They all employ an approach similar to that of OO, in which you pass an array to certain methods and then use methods as getters or setters (properties). This is supported in AutoIt.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

What is wrong with using an array and enumeration constants? You are abusing a feature that is designed for use with Dlls.

I completely disagree, but IMHO there should be nothing for you!

I just think that EVERYTHING that is likely to leave a faster script, easy to understand and maintain and why not say: Beautiful to look at or read - should be valued yes even that has not been designed for this purpose.

JS

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

This "feature" was discovered by Minx and Mars (autoit.de).

I like using structs as objects!

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

HotKeySet("{ESC}", "_Exit")

_GDIPlus_Startup()

Global $tWin = _Win_Create(0, 0, @DesktopWidth, @DesktopHeight)

Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00)



Global $fX, $fY, $fW, $fH
While Sleep(500)

    _GDIPlus_GraphicsClear($tWin.GFX, 0)

    For $i = 1 To 10
        _GDIPlus_BrushSetSolidColor($hBrush, BitOR(0x80000000, BitShift(Random(0, 0xFF, 1), -16), BitShift(Random(0, 0xFF, 1), -8), Random(0, 0xFF, 1)))
        $fW = Random(50, 300)
        $fH = Random(50, 300)
        $fX = Random(0, @DesktopWidth - $fW)
        $fY = Random(0, @DesktopHeight - $fH)

        _GDIPlus_GraphicsFillEllipse($tWin.Gfx, $fX, $fY, $fW, $fH, $hBrush)
    Next

    _Win_Draw($tWin)
WEnd



Func _Win_Create($iX, $iY, $iW, $iH)
    Local $tWin = DllStructCreate("int X; int Y; int W; int H; hwnd Gui; hwnd DC; handle GFX; handle BMP; hwnd CDC; hwnd OBJ; int Src[2]; byte Blend[4];")

    $tWin.Blend(3) = 0xFF
    $tWin.Blend(4) = 1
    $tWin.X = $iX
    $tWin.Y = $iY
    $tWin.W = $iW
    $tWin.H = $iH

    $tWin.Gui = GUICreate("", $iW, $iH, $iX, $iY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

    $tWin.DC = _WinAPI_GetDC($tWin.Gui)

    Local $hBMP = _WinAPI_CreateCompatibleBitmap($tWin.DC, $iW, $iH)
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
    _WinAPI_DeleteObject($hBMP)

    $tWin.BMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)

    $tWin.CDC = _WinAPI_CreateCompatibleDC($tWin.DC)
    $tWin.OBJ = _WinAPI_SelectObject($tWin.CDC, $tWin.BMP)

    $tWin.GFX = _GDIPlus_GraphicsCreateFromHDC($tWin.CDC)

    GUISetState(@SW_SHOWNOACTIVATE, $tWin.Gui)

    Return $tWin
EndFunc   ;==>_Win_Create


Func _Win_Dispose(ByRef $tWin)
    If Not IsDllStruct($tWin) Then Return

    _GDIPlus_GraphicsDispose($tWin.GFX)
    _WinAPI_SelectObject($tWin.CDC, $tWin.OBJ)
    _WinAPI_DeleteObject($tWin.BMP)
    _WinAPI_DeleteDC($tWin.CDC)
    _WinAPI_ReleaseDC($tWin.Gui, $tWin.DC)
    GUIDelete($tWin.Gui)
    $tWin = 0
EndFunc   ;==>_Win_Dispose


Func _Win_Draw(ByRef $tWin)
    If Not IsDllStruct($tWin) Then Return
    _WinAPI_UpdateLayeredWindow($tWin.Gui, $tWin.DC, DllStructGetPtr($tWin, "X"), DllStructGetPtr($tWin, "W"), $tWin.CDC, DllStructGetPtr($tWin, "Src"), 0, DllStructGetPtr($tWin, "Blend"), 2)
EndFunc   ;==>_Win_Draw


Func _Exit()
    _GDIPlus_BrushDispose($hBrush)
    _Win_Dispose($tWin)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

In this example I have one struct for all things I need to draw and call _WinAPI_UpdateLayeredWindow

I can add, remove or change the order of the elements without changing the rest of the script.

And the code is easy to read.

 

I like that feature/syntax too.

But I'm surprised that it works because as far as I can remember

Jon removed this from AutoIt long time ago (removing was in changelog)

after some developer added it to AutoIt and Jon disagreed and said it's against his intention.

3.2.3.13 (4th May, 2007) (Beta)

- Removed: Struct keyword and dot notation for accessing.

 

Link to comment
Share on other sites

So for those who like this style, do an appeal to Jon not remove this possibility since it only benefits us!
 

So here is my: Jon, please, do not remove this style!

JS

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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