Jump to content

Copy Struct to 2D Array


Go to solution Solved by OJBakker,

Recommended Posts

Hi 

i need to copy struct to 2D Array

but  not work

==> Variable must be of type "Object".:

#include <array.au3>

Local Const $tagObj =       "hwnd hwnd;"    & _
                            "byte ctrlID;"  & _
                            "wchar dir[6];" & _
                            "byte idBKG;"   
                            
 Local $oObj = DllStructCreate($tagObj)
 
 $oObj.hwnd = 0x1230
 $oObj.ctrlID = 2
 $oObj.dir = "left"
 
 
 local $aArray1[0]
 _arrayadd($aArray1, $oObj)
 Msgbox(64,"$aArray1[0].dir", $aArray1[0].dir) ;<----------------this work fine
 
 
 local $aArray2[0][3]
 _arrayadd($aArray2, "main1" & "|" & $oObj.hwnd & "|" & $oObj)
 Msgbox(64,"$aArray2[0][2].dir", $aArray2[0][2].dir) ;<----------------this not work , return 0 | NULL
  
 
Exit

 

 

Link to comment
Share on other sites

  • Solution

The problem is using

_arrayadd()

with the delimited-string option. Your object gets converted to string and is no longer an object when extracted. Do not use delimited-string for complex datatypes. Use the array-option to avoid undesired conversions.

#include <array.au3>

Local Const $tagObj =       "hwnd hwnd;"    & _
                            "byte ctrlID;"  & _
                            "wchar dir[6];" & _
                            "byte idBKG;"

 Local $oObj = DllStructCreate($tagObj)

 $oObj.hwnd = 0x1230
 $oObj.ctrlID = 2
 $oObj.dir = "left"


 local $aArray1[0]
 _arrayadd($aArray1, $oObj)
 MsgBox(Default, "vartype", VarGetType($aArray1[0]))
 Msgbox(64,"$aArray1[0].dir", $aArray1[0].dir)

 local $aArray2[0][3]
 local $aAddArray[1][3] = [["main1", $oObj.hwnd, $oObj]]
 _arrayadd($aArray2, $aAddArray)
 MsgBox(Default, "vartype", VarGetType($aArray2[0][2]))
 Msgbox(64,"$aArray2[0][2].dir", $aArray2[0][2].dir)
 
Exit

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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