randallc Posted August 23, 2006 Posted August 23, 2006 (edited) Hi,I had to make a workaround to get the APIWrite to work in Larry's function, but he is not replying to queries; ? a bug in the DLL functions? [DllStructCreate] etcSee.1. Working example and links to other example zip.TailRW.au3 UDF Demo2. detail below of workaround (if "+1") NOT added within the DLL "char[" creation, then written strng shortened by 1 and "chr(0)" added at end!Best, RandallFunc _APIFileWrite($hFile, $szData, $Option = 0) ;############################## ; _APIFileWrite( <FileHandle>, <Data to Write>, [ <Option 0=String | 1=Binary(hex)> ] ) ; ; For binary <Data to Write> must be comma delimited hex values. ; ; Return - # of Bytes written ; sets @error to the return from WriteFile api ;############################## ;~ $timerw = TimerInit() Local $AFW_r, $AFW_n, $AFW_i, $AFW_ptr If $Option = 0 Then $AFW_n = StringLen($szData) $AFW_ptr = DllStructCreate("char[" & $AFW_n + 1 & "]");+1; workaround fix DllStructSetData($AFW_ptr, 1, String($szData)) Else $szData = StringSplit($szData, ",") $AFW_n = $szData[0] $AFW_ptr = DllStructCreate("byte[" & $AFW_n & "]") For $AFW_i = 1 To $AFW_n DllStructSetData($AFW_ptr, 1, Dec($szData[$AFW_i]), $AFW_i) Next EndIf $AFW_r = DllCall("kernel32.dll", "int", "WriteFile", "hwnd", $hFile, "ptr", DllStructGetPtr($AFW_ptr), "long", $AFW_n, "long_ptr", 0, "ptr", 0) SetError($AFW_r[0]) $AFR_ptr = "";DllStructDelete($AFR_ptr) ;~ ConsoleWrite("_APIFileWrite time=" & TimerDiff($timerw) & @LF) Return $AFW_r[4] EndFunc ;==>_APIFileWrite Edited August 23, 2006 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
jpm Posted August 27, 2006 Posted August 27, 2006 I understand you find a bug in a non distributed API so I move the thread to support hopping Larry will answer
randallc Posted August 27, 2006 Author Posted August 27, 2006 (edited) Hi, I thought it was a bug in AutoIt "DllStructCreate" function; what do you mean by "non-distributed"? Am I wrong about that? Best, Randall [PS or DllStructSetData, DllCall, DllStructGetPtr?] Edited August 27, 2006 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
jpm Posted August 28, 2006 Posted August 28, 2006 randallc said: Hi, I thought it was a bug in AutoIt "DllStructCreate" function; what do you mean by "non-distributed"? Am I wrong about that? Best, Randall [PS or DllStructSetData, DllCall, DllStructGetPtr?]for me it is specific to your use of the _APIFileWrite as stringlen is not returning the ending chr(0) needed for a string in your case. I think Larry will confirm
randallc Posted August 28, 2006 Author Posted August 28, 2006 (edited) OK, thanks; I see the structure was calling back one too few characters for the string. It was not "my" use of the "APIwrite", though; it was a pre-written UDF which I have only changed as a workaround as it was not working accurately [deliberately perhaps???]. Thanks again for the explanation. Best, Randall Edited August 28, 2006 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
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