Sign in to follow this  
Followers 0
SumTingWong

DllCall string buffer size?

12 posts in this topic

Can anyone tell me what the buffer size is for string params passed by DllCall?

I am trying to return some values via a string but I keep getting access violation errors when exceeding a certain size.

Thanks.

Share this post


Link to post
Share on other sites



For now it's limited by 65536 bytes.

<{POST_SNAPBACK}>

DOH! :lmao:

Share this post


Link to post
Share on other sites

I was thinking for a "str:size" possibility but for now the only workaround is to make the variable you use big enough to hold the data. Then instead of using a 64KB limit autoit allows you to return something bigger.

$mybigstring = "jkj"

; Do something to $mybigstring to make it large enough to hold your return string

...

...

...

then:

DllCall(..... "str", $mybigstring, ....)

Share this post


Link to post
Share on other sites

I was thinking for a "str:size" possibility but for now the only workaround is to make the variable you use big enough to hold the data.  Then instead of using a 64KB limit autoit allows you to return something bigger.

$mybigstring = "jkj"

; Do something to $mybigstring to make it large enough to hold your return string

...

...

...

then:

DllCall(..... "str", $mybigstring, ....)

<{POST_SNAPBACK}>

Thanks, that's useful to know.

Share this post


Link to post
Share on other sites

Ok, I have found this very old topic because I have a similar problem here.

I have to use a DllCall which returns its data in "str". Although I have no errors, when the data are less than 65536 characters, they are delivered in whole. When they exceed this limit, they are delivered only up to this limit (the rest are gone).

Can somebody help me with this? I want to believe that there must be a trick...

Thank you,

Share this post


Link to post
Share on other sites

64KB is the size of the internal buffer when you use the "str" type. As piccaso said, if you're working with data larger than that, use DllStructCreate() to allocate a buffer size of your own choosing.

Share this post


Link to post
Share on other sites

Thank you very much for your answers.

However I am not that experienced with DLLs, so some guidance would be appreciated. Here is my code so far:

$dll = DllOpen("7-zip32.dll")
$check = DllCall($dll, "int", "SevenZip", "hwnd", 0, "str", "l " & Chr(34) & "just-an-archive.7z" & Chr(34), "str", "", "int", 65535)
DllClose($dll)
MsgBox(0, "", $check[3])

So, as you can see, the limitation applies to the third parameter. How would I use DllStructCreate with this? I haven't done it before...

Share this post


Link to post
Share on other sites

Anyone please?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I assumed that the last parameter is the buffer size...

$vBuff = DllStructCreate("char[1048576]") ; Size in bytes
$dll = DllOpen("7-zip32.dll")
$check = DllCall($dll, "int", "SevenZip", "hwnd", 0, _
        "str", "l " & Chr(34) & "just-an-archive.7z" & Chr(34), _
        "ptr", DllStructGetPtr($vBuff), _ ; Pass a pointer instead of 'str'
        "int", DllStructGetSize($vBuff)) ; the size of the buffer?
DllClose($dll)
MsgBox(0, "", DllStructGetData($vBuff,1))
Edited by piccaso

CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map

Share this post


Link to post
Share on other sites

picasso, you are _always_ a lifesaver. This is not the first time that I bow to your superior knowledge. Thank you mate, it works just fine!

I still can't understand very well the use of pointers and structs and I strongly believe that AU3's documentation lacks much information regarding the use of DLLs in general. I am not an experienced programmer in general, but I consider myself experienced with AutoIT. I believe that in the documentation/forum should exist some tutorials and more detailed examples, so the use of DLLs will not be limited to people with experience from other programming languages.

I know that Google is always our friend, however no matter how much information I find there, I cannot always connect the dots when trying to migrate the information to AutoIT code...

Please consider it.

Thank you once again, I really appreciate it!

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