AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Ahk2Exe.exe fails in v. 1.0.44.14

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Wdb



Joined: 27 Feb 2006
Posts: 15
Location: Italy

PostPosted: Thu Oct 19, 2006 2:11 pm    Post subject: Ahk2Exe.exe fails in v. 1.0.44.14 Reply with quote

Hi all.

In autohotkey v. 1.0.43.11 I created executable scripts with Ahk2Exe.exe without problems.

Since 1.0.44.14 my scripts doesn't work very well.

For example, in this script (compiled):
Code:
; ********************************************************************************
; *   Script Wdb_Domino_Remote_PC_Info_All.ahk                                   *
; *                                                                              *
; *     check if exists a PC in LAN                                              *
; ********************************************************************************
#Persistent
        Wdb_Pc        = JOBPC
        Wdb_In_Cmd   := comspec " /c Ping " Wdb_Pc " -n 1 -a"
        Wdb_Out_Cmd  := Wdb_CMDret_RunReturn(Wdb_In_Cmd)
        StringGetPos, Wdb_Ind, Wdb_Out_Cmd, Risposta da
        If (ErrorLevel <> 0)
        {
            MsgBox, No PC found in LAN
        } Else {
            MsgBox, PC found in LAN
        }

; ********************************************************************************
; *   Function _Wdb_CMDret_RunReturn.ahk                                         *
; *                                                                              *
; *          version 1.08 beta                                                   *
; *          Updated: March 31, 2006                                             *
; *          CMDin - command to execute                                          *
; *                                                                              *
; *          Esecuzione comando e cattura output su variabile                    *
; ********************************************************************************
Wdb_CMDret_RunReturn(CMDin)
{
    Global cmdretPID
    idltm := A_TickCount + 20
    CMsize = 1
    VarSetCapacity(CMDout, 1, 32)
    VarSetCapacity(sui,68, 0)
    VarSetCapacity(pi, 16, 0)
    VarSetCapacity(pa, 12, 0)
    Loop, 4 {
        DllCall("RtlFillMemory", UInt,&pa+A_Index-1, UInt,1, UChar,12 >> 8*A_Index-8)
        DllCall("RtlFillMemory", UInt,&pa+8+A_Index-1, UInt,1, UChar,1 >> 8*A_Index-8)
    }
    If (DllCall("CreatePipe", "UInt*",hRead, "UInt*",hWrite, "UInt",&pa, "Int",0) <> 0) {
        Loop, 4
            DllCall("RtlFillMemory", UInt,&sui+A_Index-1, UInt,1, UChar,68 >> 8*A_Index-8)
        DllCall("GetStartupInfo", "UInt", &sui)
        Loop, 4 {
            DllCall("RtlFillMemory", UInt,&sui+44+A_Index-1, UInt,1, UChar,257 >> 8*A_Index-8)
            DllCall("RtlFillMemory", UInt,&sui+60+A_Index-1, UInt,1, UChar,hWrite >> 8*A_Index-8)
            DllCall("RtlFillMemory", UInt,&sui+64+A_Index-1, UInt,1, UChar,hWrite >> 8*A_Index-8)
            DllCall("RtlFillMemory", UInt,&sui+48+A_Index-1, UInt,1, UChar,0 >> 8*A_Index-8)
        }
        If (DllCall("CreateProcess", Int,0, Str,CMDin, Int,0, Int,0, Int,1, "UInt",0, Int,0, Int,0, UInt,&sui, UInt,&pi) <> 0) {
            Loop, 4
                cmdretPID += *(&pi+8+A_Index-1) << 8*A_Index-8
            Loop {
                idltm2 := A_TickCount - idltm
                If (idltm2 < 10) {
                    DllCall("Sleep", Int, 10)
                    Continue
                }
                If (DllCall("PeekNamedPipe", "uint", hRead, "uint", 0, "uint", 0, "uint", 0, "uint*", bSize, "uint", 0 ) <> 0 ) {
                    Process, Exist, %cmdretPID%
                    If (ErrorLevel OR bSize > 0) {
                        If (bSize > 0) {
                            VarSetCapacity(lpBuffer, bSize+1)
                            If (DllCall("ReadFile", "UInt",hRead, "Str", lpBuffer, "Int",bSize, "UInt*",bRead, "Int",0) > 0) {
                                If (bRead > 0) {
                                    TRead += bRead
                                    VarSetCapacity(CMcpy, (bRead+CMsize+1), 0)
                                    CMcpy = a
                                    DllCall("RtlMoveMemory", "UInt", &CMcpy, "UInt", &CMDout, "Int", CMsize)
                                    DllCall("RtlMoveMemory", "UInt", &CMcpy+CMsize, "UInt", &lpBuffer, "Int", bRead)
                                    CMsize += bRead
                                    VarSetCapacity(CMDout, (CMsize + 1), 0)
                                    CMDout=a
                                    DllCall("RtlMoveMemory", "UInt", &CMDout, "UInt", &CMcpy, "Int", CMsize)
                                    VarSetCapacity(CMDout, -1) ; <====== needed correction since v. 1.0.44.14
                                }
                            }
                        }
                    }
                    Else
                        Break
                }
                Else
                    Break
                idltm := A_TickCount
            }
        }
        cmdretPID=
        DllCall("CloseHandle", UInt, hWrite)
        DllCall("CloseHandle", UInt, hRead)
    }
    If (StrLen(CMDout) < TRead) {
        VarSetCapacity(CMcpy, TRead, 32)
        TRead2 = %TRead%
        Loop {
            DllCall("RtlZeroMemory", "UInt", &CMcpy, Int, TRead)
            NULLptr := StrLen(CMDout)
            cpsize := Tread - NULLptr
            DllCall("RtlMoveMemory", "UInt", &CMcpy, "UInt", (&CMDout + NULLptr + 2), "Int", (cpsize - 1))
            DllCall("RtlZeroMemory", "UInt", (&CMDout + NULLptr), Int, cpsize)
            DllCall("RtlMoveMemory", "UInt", (&CMDout + NULLptr), "UInt", &CMcpy, "Int", cpsize)
            TRead2 --
            If (StrLen(CMDout) > TRead2)
                Break
        }
    }
    StringTrimLeft, CMDout, CMDout, 1
    Return, CMDout
}

the variable Wdb_Out_Cmd contains the result of the PING command in v. 1.0.43.11 while contains no data in v. 1.0.44.14

If I execute the script as is (i.e. .ahk) it works.

I suppose it depends from the Ahk2Exe.exe program that with the previous version generates correct executable programs.


Last edited by Wdb on Sun Oct 22, 2006 10:15 am; edited 4 times in total
Back to top
View user's profile Send private message
Wdb



Joined: 27 Feb 2006
Posts: 15
Location: Italy

PostPosted: Fri Oct 20, 2006 6:19 am    Post subject: Reply with quote

deleted, see up

Last edited by Wdb on Fri Oct 20, 2006 5:16 pm; edited 1 time in total
Back to top
View user's profile Send private message
Thalon



Joined: 12 Jul 2005
Posts: 640

PostPosted: Fri Oct 20, 2006 7:03 am    Post subject: Reply with quote

What should it do and what does it do?

Thalon
_________________
AHK-Icon-Changer
AHK-IRC
deutsches Forum
SacredVault
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10474

PostPosted: Fri Oct 20, 2006 8:21 am    Post subject: Reply with quote

There are no significant differences in the code between compiled scripts and normal scripts. Please ensure that you're using VarSetCapacity with DllCall properly, especially the following change in v1.0.44.14:
Quote:
Changed StrLen()/StringLen and internal string-handling to avoid calculating a string's length when possible. Although this enhances performance (especially for large strings), scripts that use DllCall to pass a string via the address operator (&) rather than as a str parameter should call VarSetCapacity(Var, -1) to correct the internally-stored length (if it changed).

The ListVars command can be used to verify that the internal length of each variable is set properly. If it isn't, the script needs to be adjusted.

If this isn't enough to help you, or if anyone else can reproduce it (preferably with a simpler script), please post here.

Thanks.
Back to top
View user's profile Send private message Send e-mail
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Fri Oct 20, 2006 9:27 am    Post subject: Reply with quote

Wdb wrote:
I fogotten a statement (the first).
Do you know that since you were logged in when posting the first message, you can edit it? Instead of pasting similar code twice, which is confusing...

And in light of the remark by Chris, I would try to add a zero parameter to the line: VarSetCapacity(lpBuffer, bSize+1)
Also majkinetor noticed that sometime, for mysterious reasons, using an initialization value different of zero makes some DllCalls work when they can fail randomly otherwise...
Stuff to experiment.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10474

PostPosted: Fri Oct 20, 2006 9:52 am    Post subject: Reply with quote

PhiLho wrote:
majkinetor noticed that sometime, for mysterious reasons, using an initialization value different of zero makes some DllCalls work when they can fail randomly otherwise...
Stuff to experiment.
That is most likely something to do with the issue quoted higher above. If not and it can be reproduced at will, I'd like to take a look at it.
Back to top
View user's profile Send private message Send e-mail
Wdb



Joined: 27 Feb 2006
Posts: 15
Location: Italy

PostPosted: Fri Oct 20, 2006 5:14 pm    Post subject: Reply with quote

First of all, thanks all for answer and sorry for my english.

PhiLho wrote:
Wdb wrote:
I fogotten a statement (the first).
Do you know that since you were logged in when posting the first message, you can edit it? Instead of pasting similar code twice, which is confusing...

Sorry, I appreciate your suggestion for next time

PhiLho wrote:
And in light of the remark by Chris, I would try to add a zero parameter to the line: VarSetCapacity(lpBuffer, bSize+1)
Also majkinetor noticed that sometime, for mysterious reasons, using an initialization value different of zero makes some DllCalls work when they can fail randomly otherwise...
Stuff to experiment.

I copied the CMDret-AHK functions from "AutoHotkey Community Forum Index -> Scripts & Functions -> Functions -> CMDret - AHK functions by corrupt ":
this script is original and not modified (I don't know very well all the statements declared, sorry) so I am not able to modify VarSetCapacity stm adding a zero parameter: do you explain me?

Finally, you can test it with this sample code:
Code:
#Persistent
        Wdb_In_Cmd   := comspec " /c Ping JOBPC -n 1 -a"
        Wdb_Out_Cmd  := Wdb_CMDret_RunReturn(Wdb_In_Cmd)
        MsgBox, %Wdb_Out_Cmd%
        ExitApp

Even if you don't compile the scripts but you execute it (.ahk or .exe), can see a MsgBox empty (not with v. 1.0.43.11).

How I can repair this problem?

Thanks all.


Last edited by Wdb on Sun Oct 22, 2006 10:16 am; edited 1 time in total
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Fri Oct 20, 2006 8:29 pm    Post subject: Reply with quote

Wdb wrote:
Sorry, I appreciate your suggestion for next time
Thank you.

Wbd wrote:
I copied the CMDret-AHK functions [...] so I am not able to modify VarSetCapacity stm adding a zero parameter [...] How I can repair this problem?
Mmm, I understand better now...
Chris is right, I overlooked that CMDout was built with RltXxx commands. You need, as advised, to add some VarSetCapacity(CMDout, -1), but I don't have much time right now to analyze the code and tell exactly where they are needed. Somebody else? corrupt would be the best people for this, but I haven't seen his posts for some time. Perhaps you should post a message in the topic you come from, if he watches it, he would be alerted.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2421

PostPosted: Sat Oct 21, 2006 4:12 pm    Post subject: Reply with quote

Thanks for making me aware of the issue Smile . I'm a bit tied up with a few projects at work and have been taking a bit of a break from unofficial projects at home but I'll have a look a bit later today.
Back to top
View user's profile Send private message Visit poster's website
Wdb



Joined: 27 Feb 2006
Posts: 15
Location: Italy

PostPosted: Sat Oct 21, 2006 4:19 pm    Post subject: Reply with quote

Ok Corrupt Very Happy

I wait Cool
Back to top
View user's profile Send private message
Wdb



Joined: 27 Feb 2006
Posts: 15
Location: Italy

PostPosted: Sun Oct 22, 2006 10:08 am    Post subject: Reply with quote

Ok, I correct the ."CORRUPT CMDret-AHK function" inserting the statement
Code:
                                    VarSetCapacity(CMDout, -1)

after the statement
Code:
                                    DllCall("RtlMoveMemory", "UInt", &CMDout, "UInt", &CMcpy, "Int", CMsize)

and the script now works wery fine even with 1.0.44.14 Very Happy

Thank Chris and PhiLho for your good suggestions
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group