Jump to content

How to use this CaptureConsole.DLL?


 Share

Recommended Posts

I try to use the DLL found here:

http://www.codeproject.com/KB/threads/CaptureConsole.aspx

This DLL let you call a console command and it returns a string with the output of the command.

I have put the file CaptureConsole.DLL in the same directory of this script

Here is my code to test this DLL (without success)

$dll = DllOpen(".\CaptureConsole.dll")

MsgBox(0,"DLLOpen return code",$dll) ; to see return code

dim $s_ApiError, $s_StdOut,  $s_StdErr

$s32_ExitCode = DllCall($dll,"str", "ExecuteA", "str", "dir c:\", "BOOL", 0, "str", "D:\Temp\au3", "str" ,"" ,"BOOL", 0, "int", 120000) ; , "str*", $s_ApiError, "str*", $s_StdOut, "str*", $s_StdErr)

MsgBox(0,"return code of DLLCall",$s32_ExitCode)

MsgBox(0,"output", $s_ApiError & " - " & $s_StdOut& " - " &  $s_StdErr) ; to see the DLL output strings???

DllClose($dll)

can someone help me to use this DLL? Thank you

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

You need to learn more before use DllCall... there`s remarks in the help file... also DllCall returns an array

EDIT Another things... Use ConsoleWrite Instead MsgBox is much effective when you want to share results.

how we gonna know what is wrong if you didn`t post the console output or the dll itself, so we can make some tests? (I preffer the consoleoutput)

Edited by monoscout999
Link to comment
Share on other sites

You need to learn more before use DllCall... there`s remarks in the help file... also DllCall returns an array

EDIT Another things... Use ConsoleWrite Instead MsgBox is much effective when you want to share results.

how we gonna know what is wrong if you didn`t post the console output or the dll itself, so we can make some tests? (I preffer the consoleoutput)

Thanks for the reply.

I have not attached the DLL because it exceeds 64k,

however, it can be downloaded from this link:

http://www.codeproject.com/KB/threads/CaptureConsole/CaptureConsole_3.3b.zip

or here:

http://www.adrive.com/public/010cd297de5b9936cef150e4c3864aa3709e3eecc4a7fec742ff7e38aab1b8c5.html

DLL description is here:

http://www.codeproject.com/KB/threads/CaptureConsole.aspx

basically can't figure out how to retrieve the output strng of the DLL

Thanks again

new code with : ConsoleWrite Instead of MsgBox

$dll = DllOpen(".\CaptureConsole.dll")

ConsoleWrite("DLLOpen return code -> " & $dll & @crlf)

dim $s_ApiError, $s_StdOut,  $s_StdErr

$s32_ExitCode = DllCall($dll,"str", "ExecuteA", "str", "dir c:\", "BOOL", 0, "str", "D:\Temp\au3", "str" ,"" ,"BOOL", 0, "int", 120000) ; , "str*", $s_ApiError, "str*", $s_StdOut, "str*", $s_StdErr)

ConsoleWrite ("DllCall exit code -> " & $s32_ExitCode & @crlf)

ConsoleWrite("$s_ApiError ->" & $s_ApiError & @crlf  & "$s_StdOut -> " & $s_StdOut & @crlf  & "$s_StdErr -> " &  $s_StdErr & @crlf)

DllClose($dll)

output with blank result:

DLLOpen return code -> 1

DllCall exit code -> 0

$s_ApiError ->

$s_StdOut ->

$s_StdErr ->

Edited by Pincopanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

For Non-english system, the return of StdoutRead() usually includes garbled characters

Hmm, interesting... I've never encountered that problem, I'm multilingual and use different PCs with different language packs but I guess it would only apply to language characters such as Japanese, Chinese or related languages which are moon talk to me.

Dll calls aren't to difficult once you understand which array variable you need to look for, try calling the dll exported function and viewing the return variables.

Something like-

#Include<Array.au3>
$Ret = DllCall()
_Arraydisplay($Ret)

Edit: It would be awesome if you uploaded the dll to another site cause I don't think anyone wants to create an account just to download a dll and figure out how to use it appropriately.

Edited by THAT1ANONYMOUSEDUDE
Link to comment
Share on other sites

Hmm, interesting... I've never encountered that problem, I'm multilingual and use different PCs with different language packs but I guess it would only apply to language characters such as Japanese, Chinese or related languages which are moon talk to me.

Dll calls aren't to difficult once you understand which array variable you need to look for, try calling the dll exported function and viewing the return variables.

Something like-

#Include<Array.au3>
$Ret = DllCall()
_Arraydisplay($Ret)

Edit: It would be awesome if you uploaded the dll to another site cause I don't think anyone wants to create an account just to download a dll and figure out how to use it appropriately.

Mmm, I'm using Chinese. For following codes, I occasionally got garbled characters

(BTW: Pincopanco, you could use following codes, then not need to call that DLL)

#include <ButtonConstants.au3>
#include <GUIButton.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GUIImageList.au3>
#include <GuiEdit.au3>
#include <WinAPIEx.au3>


$HDL = Run(@ComSpec, "", @SW_HIDE, $STDIN_CHILD + $STDERR_MERGED)
$GUIID = GUICreate("CMDshell", 600, 750)
$DISP = GUICtrlCreateEdit("", 10, 10, 580, 700, $Es_READONLY + $WS_VSCROLL + $WS_HSCROLL + $ES_OEMCONVERT)
GUICtrlSetLimit(-1, 1024 * 1024)
GUICtrlSetFont(-1, 9, 200, 0)
GUICtrlSetBkColor($DISP, 0x000000)
GUICtrlSetColor($DISP, 0x00FF00)
$CMDS = GUICtrlCreateEdit("commands...", 10, 720, 530, 20)
GUICtrlSetBkColor($CMDS, 0x000000)
GUICtrlSetColor($CMDS, 0xFFFFFF)
GUISetBkColor(0x000000)
$Dummy = GUICtrlCreateDummy()
GUISetState()

Local $Key[1][2] = [["{Enter}", $Dummy]]
GUISetAccelerators($Key)
_GUICtrlEdit_SetSel($CMDS, 0, -1)

While True
    $guimsg = GUIGetMsg()
    Switch $guimsg
        Case $GUI_EVENT_CLOSE
            ProcessClose("cmd.exe")
            Exit
        Case $Dummy
            Local $aResult = DllCall("user32.dll", "hwnd", "GetFocus")
            If $aResult[0] = GUICtrlGetHandle($CMDS) Then
                If _GUICtrlEdit_GetText($CMDS) = "cls" Then _GUICtrlEdit_SetText($DISP, "")
                If _GUICtrlEdit_GetText($CMDS) = "exit" Then
                    ProcessClose("cmd.exe")
                    Exit
                EndIf
                StdinWrite($HDL, _GUICtrlEdit_GetText($CMDS) & @CRLF)
                _GUICtrlEdit_SetSel($CMDS, 0, -1)
            EndIf
    EndSwitch

    $msg = StdoutRead($HDL)
    If $msg <> "" Then
        If _GUICtrlEdit_GetLineCount($DISP) > 500 Then
            _GUICtrlEdit_SetText($DISP, "")
        EndIf
        _GUICtrlEdit_AppendText($DISP, $msg)
        $msg = ""
    EndIf
WEnd
Link to comment
Share on other sites

AutoIt has a OEM function that lets you do that without the dll.

Try-

$Run = Run(@ComSpec & 'Commands go here', "", @SW_HIDE, 2 + 4)
While 1
    $Out = StdoutRead($Run)
    If @error Then ExitLoop
WEnd
MsgBox(0, "AutoThis", $Out)

Hello, Thanks for Your reply.

With this code, I get only an empty MessageBox.

I changed

$Run = Run(@ComSpec & 'Commands go here', "", @SW_HIDE, 2 + 4)

with

$Run = Run(@ComSpec & 'dir c:\', "", @SW_HIDE, 2 + 4)

other times I try this I got the same problem, an empty $Out

bye

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Hello, Thanks for Your reply.

With this code, I get only an empty MessageBox.

I changed

$Run = Run(@ComSpec & 'Commands go here', "", @SW_HIDE, 2 + 4)

with

$Run = Run(@ComSpec & 'dir c:\', "", @SW_HIDE, 2 + 4)

other times I try this I got the same problem, an empty $Out

bye

Well, of course you're gonna get a null return without adding an actual command that comhost could process...

Any way, hope you don't need that dll any more.

Link to comment
Share on other sites

Try this:

#include <Constants.au3>


$Re = Commander("dir c:\")
MsgBox(0,0,$Re)

Func Commander($Prompt)
    Local $Pid, $Stream, $Flag = 0
    
    $Pid = Run(@ComSpec & " /c " & $Prompt, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    While True
        $Stream &= StdoutRead($Pid)
        If @error Then 
            If $Flag == 2 Then
                $Flag = 0
                ExitLoop
            ElseIf $Flag == 1 Then
                Sleep(250)
                $Flag = 2
                ContinueLoop
            Else
                Sleep(250)
                $Flag = 1
                ContinueLoop
            EndIf
        EndIf
    Wend

    While True
        $Stream &= StderrRead($Pid)
        If @error Then 
            If $Flag == 2 Then
                $Flag = 0
                ExitLoop
            ElseIf $Flag == 1 Then
                Sleep(250)
                $Flag = 2
                ContinueLoop
            Else
                Sleep(250)
                $Flag = 1
                ContinueLoop
            EndIf
        EndIf
    WEnd
    
    $Stream = DllCall('user32.dll','Int','OemToChar','str',$Stream,'str','')
    $Stream = $Stream[2]
    Return $Stream
EndFunc
Link to comment
Share on other sites

Hmm, interesting... I've never encountered that problem, I'm multilingual and use different PCs with different language packs but I guess it would only apply to language characters such as Japanese, Chinese or related languages which are moon talk to me.

Dll calls aren't to difficult once you understand which array variable you need to look for, try calling the dll exported function and viewing the return variables.

Something like-

#Include<Array.au3>
$Ret = DllCall()
_Arraydisplay($Ret)

Edit: It would be awesome if you uploaded the dll to another site cause I don't think anyone wants to create an account just to download a dll and figure out how to use it appropriately.

I have try this code inside my script but I get no output from the _Arraydisplay() function.

P.S.

here an alternative link to download the ZIP file that contains the Dll (located in CaptureConsole 3.3b\Release_32\ inside the zip file):

http://www.adrive.com/public/010cd297de5b9936cef150e4c3864aa3709e3eecc4a7fec742ff7e38aab1b8c5.html

Edited by Pincopanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Try this:

#include <Constants.au3>


$Re = Commander("dir c:\")
MsgBox(0,0,$Re)

Func Commander($Prompt)
    Local $Pid, $Stream, $Flag = 0
    
    $Pid = Run(@ComSpec & " /c " & $Prompt, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    While True
        $Stream &= StdoutRead($Pid)
        If @error Then 
            If $Flag == 2 Then
                $Flag = 0
                ExitLoop
            ElseIf $Flag == 1 Then
                Sleep(250)
                $Flag = 2
                ContinueLoop
            Else
                Sleep(250)
                $Flag = 1
                ContinueLoop
            EndIf
        EndIf
    Wend

    While True
        $Stream &= StderrRead($Pid)
        If @error Then 
            If $Flag == 2 Then
                $Flag = 0
                ExitLoop
            ElseIf $Flag == 1 Then
                Sleep(250)
                $Flag = 2
                ContinueLoop
            Else
                Sleep(250)
                $Flag = 1
                ContinueLoop
            EndIf
        EndIf
    WEnd
    
    $Stream = DllCall('user32.dll','Int','OemToChar','str',$Stream,'str','')
    $Stream = $Stream[2]
    Return $Stream
EndFunc

Hello,

Thanks for Your replys and nice code.

P.S.

I try this command:

$Re = Commander("tree c:\ /A")

..... but autoit crashes :mellow:

maybe too long output

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...