Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

How to use this CaptureConsole.DLL?


  • Please log in to reply
12 replies to this topic

#1 Chimp

Chimp

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 859 posts

Posted 17 August 2011 - 04:12 PM

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

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








#2 monoscout999

monoscout999

    a member

  • Active Members
  • PipPipPipPipPipPip
  • 1,064 posts

Posted 17 August 2011 - 04:17 PM

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, 17 August 2011 - 04:19 PM.


#3 CaptainClucks

CaptainClucks

    Unum Cavillator Spuria

  • Active Members
  • PipPipPipPipPipPip
  • 1,224 posts

Posted 17 August 2011 - 04:31 PM

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)

Spoiler
Warning: Posts by this user are subject to change or may disappear without notice.

#4 Chimp

Chimp

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 859 posts

Posted 17 August 2011 - 05:10 PM

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, 17 August 2011 - 11:49 PM.

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


#5 monoscout999

monoscout999

    a member

  • Active Members
  • PipPipPipPipPipPip
  • 1,064 posts

Posted 17 August 2011 - 05:11 PM

DllCall returns an array... look in the helpfile

#6 happytc

happytc

    Adventurer

  • Active Members
  • PipPip
  • 119 posts

Posted 17 August 2011 - 07:16 PM

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)

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

#7 CaptainClucks

CaptainClucks

    Unum Cavillator Spuria

  • Active Members
  • PipPipPipPipPipPip
  • 1,224 posts

Posted 17 August 2011 - 07:45 PM

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, 17 August 2011 - 07:48 PM.

Spoiler
Warning: Posts by this user are subject to change or may disappear without notice.

#8 happytc

happytc

    Adventurer

  • Active Members
  • PipPip
  • 119 posts

Posted 17 August 2011 - 08:13 PM

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)
Plain Text         
#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


#9 Chimp

Chimp

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 859 posts

Posted 17 August 2011 - 09:23 PM

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

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


#10 CaptainClucks

CaptainClucks

    Unum Cavillator Spuria

  • Active Members
  • PipPipPipPipPipPip
  • 1,224 posts

Posted 17 August 2011 - 09:31 PM

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.
Spoiler
Warning: Posts by this user are subject to change or may disappear without notice.

#11 happytc

happytc

    Adventurer

  • Active Members
  • PipPip
  • 119 posts

Posted 17 August 2011 - 09:57 PM

Try this:

Plain Text         
#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


#12 Chimp

Chimp

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 859 posts

Posted 17 August 2011 - 10:50 PM

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, 17 August 2011 - 11:54 PM.

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


#13 Chimp

Chimp

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 859 posts

Posted 17 August 2011 - 10:57 PM

Try this:

Plain Text         
#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

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users