Sign in to follow this  
Followers 0
randallc

? bug in DLL function?

5 posts in this topic

#1 ·  Posted (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] etc

See.

1. Working example and links to other example zip.

TailRW.au3 UDF Demo

2. 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, Randall

Func _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 by randallc

Share this post


Link to post
Share on other sites



I understand you find a bug in a non distributed API so I move the thread to support hopping Larry will answer :P

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by randallc

Share this post


Link to post
Share on other sites

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 :P

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by randallc

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