xroot Posted October 18, 2009 Share Posted October 18, 2009 I want to load DllStructCreate return variables into a Scripting.Dictionary object.MSDN says, Scripting.Dictionary Items can be ANY FORM OF DATA, and are stored in the array.Each item is associated with a unique key.The key is used to retrieve an individual item and is usually an integer or a string,but can be anything except an array.Can someone tell me what kind of value or data type is "DllStruc"??Help says, the return value for DllStructCreate is a VARIABLE for use with DllStruct calls.Does this mean my variable $ds is a variable of a variable?I would think it should be a pointer, but when you look @ it.. shows Blank. and @error=0.Again, VarGetType($ds) shows a "DllStruc" data type. If "DllStruc" is a variant data type Scripting.Dictionary should work.This is the error I get.AutoIt Error$sd.Add($XX,$DllStruc)$sd.Add($XX,$DllStruc)^ ERRORError: The requested action with this object has failed.Global $XX=0 $sd=ObjCreate("Scripting.Dictionary") Func AddDS($DllStruc) $XX+=1 $sd.Add($XX,$DllStruc) EndFunc $dS=DllStructCreate("int") AddDS($dS) Link to comment Share on other sites More sharing options...
Authenticity Posted October 18, 2009 Share Posted October 18, 2009 It's sort of a value known to those DllStruct* functions which is something that AutoIt can only understand... or not. I think you want to use DllStructGetPtr() instead, if it's valid to send process pointers to a COM object. Link to comment Share on other sites More sharing options...
monoceres Posted October 18, 2009 Share Posted October 18, 2009 Don't use DllStructGetPtr(), because this will not increase the reference count for the DllStruct so when the dllstruct variable gets out of scope the data will be destroyed thus rendering the pointer useless.Instead dump the entire struct as a binary string.Example (note that this will only work for structs that doesn't contain pointers, if you wish to have pointers as well you'll have to expand them manually):$Rect=DllStructCreate("int;int;int;int") DllStructSetData($Rect,1,0) DllStructSetData($Rect,2,0) DllStructSetData($Rect,3,@DesktopWidth) DllStructSetData($Rect,4,@DesktopHeight) $bin=DllStruct2Binary($Rect) MsgBox(0,"",$bin) Func DllStruct2Binary($struct) $tempstruct=DllStructCreate("byte["&DllStructGetSize($struct)&"]",DllStructGetPtr($struct)) Return DllStructGetData($tempstruct,1) EndFuncTo get the struct again, just reverse the process Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Authenticity Posted October 18, 2009 Share Posted October 18, 2009 Don't use DllStructGetPtr(), because this will not increase the reference count for the DllStruct so when the dllstruct variable gets out of scope the data will be destroyed thus rendering the pointer useless.Anything that is out of scope will eventually be garbage collected. I don't get why would you need to store a pointer to data that you can't reference either way. I guess that it's totally useless to save the pointer to the data other than sending it or preparing it for a function call or other things while the structure is still in context. You can allocate memory yourself though. So, agreed monoceres, serializing the data as a good option under some circumstances. Link to comment Share on other sites More sharing options...
monoceres Posted October 18, 2009 Share Posted October 18, 2009 To clarify: ; Abstract example $Dictionary=CreateDict() AddStructToDict($Dictionary) Func AddStructToDict(ByRef $dict) $struct=DllStructCreate("int") AddValToDict($dict,DllStructGetPtr($struct)) ; Struct will now go out of scope, the pointer in dict is now useless ; Even if it still exists in dict Return EndFunc Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now