Ontosy

dllcall return string as array

13 posts in this topic

I have a dllcall that return a value that I have to convert:

func joinString($Buffer, $size, $field)
    local $ret="", $i
    For $i = 1 to $size
        $ret &= StringStripWS(DllStructGetData($Buffer, $field, $i), 15)
    Next
    return $ret
EndFunc

Do it is normal or it have a other via?

Share this post


Link to post
Share on other sites



I don't think that's normal.

Even though you're too vague, my guess is that your buffer isn't created correctly to begin with. I've noticed that unexperienced users have troubles reading and interpreting the APIs documentation correctly. Your $Buffer should be correctly sized "byte" array in case that API advertises null-separated character arrays (strings). Only then you can get all the strings out of the buffer.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

I have:

typedef struct _FbwfCacheDetail{
   ULONG cacheSize;
   ULONG openHandleCount;
   ULONG fileNameLength;
   WCHAR fileName[1];
} FbwfCacheDetail, *PFbwfCacheDetail;

And convert to:

$size=4192;

$FbwfCacheDetail=DllStructCreate("ULONG cacheSize; ULONG openHandleCount; ULONG fileNameLength; WCHAR fileName[" & $size & "];")

Do it is right?

Share this post


Link to post
Share on other sites

It depends on how you get $size and what it really represents.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

"size [in, out] On input, contains the size of cacheDetail. If the function returns ERROR_MORE_DATA, size contains the size of the required buffer."

i trigger ERROR_MORE_DATA and get $size.

Edited by Ontosy

Share this post


Link to post
Share on other sites

I think buffer talks about  whole structure. (I'M  not over my machine to try out) 

So maybe you need to subtract other fields(ulong * 3)  or just allocate memory then used the pointer with your structure. 

 

Saludos

Share this post


Link to post
Share on other sites

So you have to subtract the size of first three fields and then divide the result by 2 (1 wchar is 2 bytes).


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

trancexx. it's right (I forgot  to divide). So my second solution is wrong. I forgot Autoit structures are fixed size.

 

Saludos

Edited by Danyfirex

Share this post


Link to post
Share on other sites

 

So maybe you need to subtract other fields(ulong * 3)  or just allocate memory then used the pointer with your structure.

What is the size of fields(ulong * 3)?

Share this post


Link to post
Share on other sites

 

What is the size of fields(ulong * 3)?

I meant same as trancexx's answer.

Saludos

Share this post


Link to post
Share on other sites

f.e. if $size is 69 WCHAR fileName size is (69-3)/2 =33 ?
i'm not able to see size of fields(ulong * 3) in the trancexx's answer.

Share this post


Link to post
Share on other sites

Look:

$size = 4192;
$size -= (3 * 4);3=your first 3  fields   4=size of Ulong in bytes
$size /= 2 ;divide by size of wchar(2 bytes)
$FbwfCacheDetail = DllStructCreate("ULONG cacheSize; ULONG openHandleCount; ULONG fileNameLength; WCHAR fileName[" & $size & "];")

Saludos

Share this post


Link to post
Share on other sites

Ty, the calcule now is precise.
But i have every to use iteration to obtain the string.
If i use simple
DllStructGetData($FbwfCacheDetail, "fileName")
i obtain "2".

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