Sign in to follow this  
Followers 0
tomaskir

DllStructCreate() return value

10 posts in this topic

#1 ·  Posted (edited)

Hey guys,

I have a question regarding the return value of DllStructCreate(). Help says its a variable, but, apparently its value is an empty string. Its not an array either, so im not sure what it is.

I have 2 scripts which are to comunicate with each other using data in a structure. One script creates the structure and writes to it and the other reads data from the structure. Since the 2nd script needs to know the structure "handle" I need to pass it to that script. However, since the variable presents itself as an empty string, I cant.

Thanks in advance,

tom

Edited by tomaskir

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

It does not return a string or a handle, it returns a structure used in the dll* functione

$var = DllStructCreate("int;int;word")

ConsoleWrite(VarGetType($var) & @LF)

EDIT:

As a wild guess, and I'm going out on a limb here, I'd suggest what you want to pass to this other script is a pointer to that structure.

$DllStructCreate = DllStructCreate("int;int;word")
$DllStructGetPtr DllStructGetPtr($DllStructCreate)
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Script 1 does this basicly:

$struct_fields = "uint var1; boolean var2; uint var3"
$struct = DllStructCreate($struct_fields)

$script2_PID = run("script2.exe " & $struct)

$continue = 1
While $continue = 1
   $continue = MsgBox(1,"","data in structure: " & DllStructGetData($struct, "var1") & @CRLF & @CRLF & "OK to go again, Cancel to exit.")
WEnd

ProcessClose($script2_PID)
$struct = 0

and script 2 when called by script1:

Opt("MustDeclareVars", 1)
Local $struct
Local $count = 0

MsgBox("","","Number of arguments passed: " & $CmdLine[0])

if $CmdLine[0] <> 1 Then Exit

$struct = $CmdLine[1]

while True
   Sleep(1000)
   $count += 1
   DllStructSetData($struct, "var1", $count)
WEnd

Basicly, script2 will increase the var1 in the structure by 1 every second, i use it as a clocking mechanism of sorts :)

I searched around but cant really find a way how to make this work. Is there any way to get the structure to be used in script2?

Edited by tomaskir

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

And that works?

Where does "$struct_Hnd1" come from?

It doesnt work sadly.

Fixed the above code, mystake when copypasting :)

EDIT: Basicly, script2 is supposed to write to the structure that script1 creates. Script1 then reads from it.

Edited by tomaskir

Share this post


Link to post
Share on other sites

It doesnt work sadly.

Fixed the above code, mystake when copypasting.

You haven't really because you would still get an "error variable used without being declared" error in script 1

This leads me to believe you either 1, have not even ran that code, or 2, have more in the script.

Regardless, here is how what you are attempting could work, in pseudo form.

You create a struct

You get a pointer to that struct

You pass the pointer to script 2

Script2 to writes to the elements of that structure, based on the pointer to it (address at memory)

Script 1 can now read the changed values of the structure

Passing just a structure is worthless on its own.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You haven't really because you would still get an "error variable used without being declared" error in script 1

This leads me to believe you either 1, have not even ran that code, or 2, have more in the script.

Regardless, here is how what you are attempting could work, in pseudo form.

You create a struct

You get a pointer to that struct

You pass the pointer to script 2

Script2 to writes to the elements of that structure, based on the pointer to it (address at memory)

Script 1 can now read the changed values of the structure

Passing just a structure is worthless on its own.

Fixed it again, and ran to test, sry. Basicly, the variable $structure is named $structure_Hndl in my script, thats why it was there from copy pasting. But since its not actually a handle i renamed it :)

If I pass the pointer to script2, do i actually have to do memory writing to that address or is there a function I can use like DllStructSetData?

And thanks for the patience with me.

Edited by tomaskir

Share this post


Link to post
Share on other sites

Alright, figured it out and have it working, thanks a lot man!

I passed the pointer to script2 and then used NomadMemory UDF to write to that pointer.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

That's the ticket, Script 2 needs to write to memory in that fashion, but Script 1 can use DllStructGet/SetData.

If both scripts are writing and reading to these addresses, It might be wise to set a flag in the structure too.

Read flag.

If not set.

Set flag.

Write to address.

Unset flag.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

That's the ticket, Script 2 needs to write to memory in that fashion, but Script 1 can use DllStructGet/SetData.

If both scripts are writing and reading to these addresses, It might be wise to set a flag in the structure too.

Read flag.

If not set.

Set flag.

Write to address.

Unset flag.

I can understand how that is usefull / needed, thanks for the tip.

I will implement the flag and also some kind of mechanism for script2 to detect when it should be closed, since atm script1 is doing ProcessClose() to it, which is less then optimal.

Thanks again for all the help.

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