Sign in to follow this  
Followers 0
Ascend4nt

DLL return of str\wstr, fixed to receive 65536 chars?

4 posts in this topic

Okay, don't mean to be greedy with questions, but this question has been sitting in the Help forum for a couple of weeks, so I'm reposting it here:

It was pointed out to me that DLLCall's will automatically set up a return buffer for datatypes marked as "str" or "wstr". The way I've been coding it is to use DLLStructCreate("wstr[#]") and send it as a pointer to ensure that I have a buffer large enough to receive the data.

However, I have been told that instead, I can pretty much take it as a given that if I simply put "str" or "wstr", AutoIT will set up a default buffer (and it was mentioned that this buffer will be 65536 chars/wchars). I know the help file describes a 'maximum' of the same, but I thought this was intended for passing data *to* a DLL call though?

So, I'd just like to know if I can rely on this automatically allocated return-buffer setup or not.

For an example (cut from '_WinAPI_ProcesGetFileName'):

$stImageFilename=DllStructCreate("wchar[32767]")
$aRet=DllCall("Psapi.dll","dword","GetProcessImageFileNameW","ptr",$hProcess[0],"ptr", _
        DllStructGetPtr($stImageFilename),"ulong",32767)

Would this be able to be replaced with:

$aRet=DllCall("Psapi.dll","dword","GetProcessImageFileNameW","ptr",$hProcess[0],"wstr","","ulong",32767)

Clarification is much appreciated, thanks,

Ascend4nt

Share this post


Link to post
Share on other sites



I found a function where wstr doesn't work (ReadConsoleW). I always got some additional characters from the console window. So i created a wchar-Buffer and now it works.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

IIRC you pass "wstr*", not "wstr". But it is not necessary to allocate your own buffer.

Share this post


Link to post
Share on other sites

Through testing, "wstr*" doesn't work, but "wstr" does. Couldn't tell you why. I wonder why its not working for ProgAndy..

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