Streaming example (ANSI or UNICODE 32bit _L)
Code:
; ---------------------------------------------------------------------------
; CMDret 4b - Beta test
; March 15, 2012 - corrupt
;
; cmdret version 4b or above required
; _L ANSI or UNICODE 32bit compatibile
; ---------------------------------------------------------------------------
Gui, Add, Edit, x6 y50 w420 h590 +WantReturn HwndEd1,
Gui, Add, Button, x6 y10 w100 h30 gRunCMD, Run Command
Gui, Add, Edit, x116 y10 w200 h30 -Multi vcmd1, ping 127.0.0.1 -n 10
Gui, Add, Button, x327 y10 w100 h30 gClr, Clear
Gui, Add, StatusBar, , Ready
Gui, Show, h666 w432, CMDret 4b - Beta
Return
GuiClose:
ExitApp
RunCMD:
Gui, Submit, NoHide
If not EnumAddress
EnumAddress := RegisterCallback("cmdoutProc", "", 4)
SB_SetText("Executing... Hold <Esc> to terminate")
; ---------------------------------------------------------------------------
; RunWCB -> CMD=command to execute, EnumAddress=Address from RegisterCallback
; ---------------------------------------------------------------------------
RetVal := DllCall("cmdret.dll\RunWCB", A_IsUnicode ? "AStr" : "Str", cmd1, "UInt", EnumAddress)
If !(RetVal)
SB_SetText("Failed to Execute...")
Else
SB_SetText("Ready")
Return
cmdoutProc(cmdpid, nchar, cmdout, FutureUse)
{
global Ed1 ; Edit control HWND
; ---------------------------------------------------------------------------
Static df_lstrcat
Static df_SendMessage
If !(df_lstrcat)
df_lstrcat := DllCall("GetProcAddress", UInt, DllCall("GetModuleHandle", Str, "kernel32"), A_IsUnicode ? "AStr" : "Str", "lstrcat")
If !(df_SendMessage)
df_SendMessage := DllCall("GetProcAddress", UInt, DllCall("GetModuleHandle", Str, "user32"), A_IsUnicode ? "AStr" : "Str", "SendMessageA")
; ---------------------------------------------------------------------------
; Values returned:
; cmdpid = ProcessId
; ** = WM_USER + 1
; nchar = number of characters returned in the buffer
; cmdout = pointer to the buffer
; FutureUse = FutureUse
; ---------------------------------------------------------------------------
VarSetCapacity(TOut, nchar + 1, 0)
DllCall(df_lstrcat, "str", TOut, "UInt", cmdout)
VarSetCapacity(TOut, -1)
StripNull(TOut, nchar) ; remove NULL characters from output
DllCall(df_SendMessage, "UInt", Ed1, "UInt", 0xC2, "UInt", 0, "UInt", &TOut)
If (GetKeyState("Esc" , "P")) {
Process, Close, %cmdpid%
DllCall(df_SendMessage, "UInt", Ed1, "UInt", 0xC2, "UInt", 0, "Str", "`r`n`r`n<< Process Terminated by Esc Key >>")
}
Sleep, 0 ; short sleep to allow minimizing/restoring window
Return TRUE
}
StripNull(Var1, DataSize)
{
Local Static df_RtlZeroMemory
If !(df_RtlZeroMemory)
df_RtlZeroMemory := DllCall("GetProcAddress", uint, DllCall("GetModuleHandle", str, "kernel32"), A_IsUnicode ? "AStr" : "Str", "RtlZeroMemory")
Var1 := A_IsUnicode ? StrGet(&Var1, "cp0") : Var1
IF (StrLen(Var1) < (DataSize - 1)) {
VarSetCapacity(CMcpy, DataSize, 32)
DataSize2 = %DataSize%
Loop {
DllCall(df_RtlZeroMemory, "UInt", &CMcpy, Int, DataSize)
NULLptr := StrLen(Var1)
cpsize := DataSize - NULLptr
DllCall(df_RtlZeroMemory, "UInt", &CMcpy, "UInt", (&Var1 + NULLptr + 2), "Int", (cpsize - 1))
DllCall(df_RtlZeroMemory, "UInt", (&Var1 + NULLptr), Int, cpsize)
DllCall(df_RtlZeroMemory, "UInt", (&Var1 + NULLptr), "UInt", &CMcpy, "Int", cpsize)
DataSize2 --
IF (StrLen(Var1) > DataSize2)
break
}
}
VarSetCapacity(Var1, -1)
Return Var1
}
Clr:
GuiControl,, Edit1,
SB_SetText("Ready")
Return