HopJokey Posted July 9, 2009 Posted July 9, 2009 (edited) Hello, I am currently trying to increase the STDOUT buffer size of my script. I'm trying to use DllCall using setbuf() and I am having a hard time obtaining the File handle of STDOUT for the script. Here is the header of setbuf(): void setbuf( FILE *stream, char *buffer ); Here is my AutoIt script code that attempts to increase the buffer size of STDOUT: Global Const $gc_strStandardCLib = "msvcrt.dll" ;Name of dll that contains setbuf() Global Const $gc_filePtrStdOut = 1 ;File handle of STDOUT Global Const $gc_intStdOutBufferSize = 102400 ;Size in bytes of our standard out buffer Global $ga_intStdOutBuffer = DllStructCreate( "char[" & $gc_intStdOutBufferSize & "]" ) ;Buffer used for standard out ;Increase the buffer size of STDOUT to ensure we do not overflow the buffer DllCall( $gc_strStandardCLib, "none", "setbuf", "ptr", $gc_filePtrStdOut, "ptr", DllStructGetPtr( $ga_intStdOutBuffer ) ) The problem I am having is with the first parameter of setbuf() ("FILE *stream") which I need to pass in STDOUT to. Anyone have any suggestions? Thanks. Edited July 9, 2009 by HopJokey
Valik Posted July 11, 2009 Posted July 11, 2009 The only reliable method I can find is to use _fdopen() to bind the file descriptor for stdout to a FILE* handle. The symbolic constants stdin, stdout and stderr cannot be accessed and are actually a little more complex than I thought. At any rate, the file descriptors for the standard streams are:0 = stdin 1 = stdout 2 = stderrSo in C++ the code would look something like:FILE *fptr = _fdopen(1, "a+"); setvbuf(fptr, pBuffer, mode, buffer_size);
trancexx Posted July 11, 2009 Posted July 11, 2009 So in AutoIt that could likely be: ConsoleWrite(@CRLF) Global $iFile = 1 ; STDOUT Global $iSize = 102400 ; size in bytes (chars) Global $tBuffer = DllStructCreate("char[" & $iSize & "]") ; char buffer Global $aCall = DllCall("msvcrt.dll", "ptr:cdecl", "_fdopen", _ "ptr", $iFile, _ ; handle to open file "str", "a+") ; opens for reading and appending; creates the file first if it doesn’t exist ; error checking missing Global $hFile = $aCall[0] ConsoleWrite("! $hFile = " & $hFile & @CRLF) Global Const $IOFBF = 0 $aCall = DllCall("msvcrt.dll", "int:cdecl", "setvbuf", _ "ptr", $hFile, _ ; file "ptr", DllStructGetPtr($tBuffer), _ ; allocated buffer "int", $IOFBF, _ ; mode of buffering _IOFBF (full buffering) "dword", DllStructGetSize($tBuffer)) ; buffer size in bytes ; error checking missing ConsoleWrite(">setvbuf returned: " & $aCall[0] & @CRLF) ;<- if 0 then OK ConsoleWrite(@CRLF) ♡♡♡ . eMyvnE
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