Jump to content
Sign in to follow this  
Gui

Kernel32 DllCall Help

Recommended Posts

Gui

So, it's with a CUI, and I'm attempting to call 2 kernel functions:

SetConsoleMode
WriteConsole

SetConsoleMode will enable the user to append text, and make it non-read only.

WriteConsole is self explanatory.

PS: The difference than say maybe DConsole.au3, is that with Dll calling here, for the CUI to be shown, the script does not need to be compiled.

For their Dll Parameter info, I could only find it here (it's syntax is C#):

// http://pinvoke.net/default.aspx/kernel32/WriteConsole.html
    [DllImport("kernel32.dll", SetLastError = true)]
    static extern bool WriteConsole(
        IntPtr hConsoleOutput,
        string lpBuffer,
        uint nNumberOfCharsToWrite,
        out uint lpNumberOfCharsWritten,
        IntPtr lpReserved
        );


    // http://pinvoke.net/default.aspx/kernel32/SetConsoleMode.html
    [DllImport("kernel32.dll", SetLastError = true)]
    static extern bool SetConsoleMode(
        IntPtr hConsoleHandle,
        uint dwMode
        );

Could someone good with Dll's please convert them into AutoIt Syntax? Thanks.

Edited by Gui

Share this post


Link to post
Share on other sites
AdmiralAlkex

For their Dll Parameter info, I could only find it here (it's syntax is C#):

FYI, if you Google the name of the function you'll get their MSDN-pages as the first result.

Share this post


Link to post
Share on other sites
Gui

Thanks @Alkex, but I still can't seem to get it. Like I said I'm bad with Dlls.. This is what I'm trying: (don't laugh it's insanely wrong)

$ret = DllCall("Kernel32.dll", "hwnd", "AllocConsole")
    Local $ret = DllCall("Kernel32.dll", "hwnd", "GetStdHandle", "int", -11) ; $STD_OUTPUT_HANDLE = -11
    $hConsole = $ret[0]
    
    Local $lpNumber = DllStructCreate("dword")
    Local $nSymbolsRead = 100
    Local $lpOut = ''
    Local $lpCharacter = DllStructCreate("Text")
    Local $ret = DllCall("Kernel32.dll", "bool", "WriteConsole", "int", $hConsole, _
                                                    "ptr", DllStructGetPtr($lpCharacter), _
                                                    "dword", "4", _
                                                    "lpdword", DllStructGetPtr($lpOut), _
                                                    "null", "null")
    MsgBox(0,'',DllStructGetData($lpOut, 1) & @CRLF & $ret)

Share this post


Link to post
Share on other sites
monoscout999

Look and read the whole DllCall help from autoit. because you didn`t do that.

I suggest read whole documentation about the stuff that you are doing.

Also you can check and compare anothers DllCalls ffom UDFs(looking the UDF and the MSDN documentation as well)

It is important that you read the MSDN documentation of any windows API you want to use.

EDIT: i Almost forgot, i see one error in the parameters types.

EDIT2: You have several errors but form your script to... You are calling a dll and storing the array value in a a variable $ret, the next line you are declaring as local the $ret variable and store in them anoter DllCall return. that don`t have any logic. why you are saving the return the first time if in the next line you will overwrite the variable?

Edited by monoscout999

Share this post


Link to post
Share on other sites
Gui

I just looked over dlls, and finally figured it out. I was doing a shit load of useless storing.

I got writing to the console solved. Now all that's left is enabling user input. So far I tried this:

$aCall = DllCall("kernel32.dll", "ptr", "CreateConsoleScreenBuffer", "dword", BitOR(0x40000000, 0x80000000), "dword", 0x00000002, "ptr", 0, "dword", 1, "ptr", 0)
    Local $hBuff = $aCall[0]
    $aCall = DllCall("kernel32.dll", "int", "SetConsoleMode", "ptr", $hBuff, "dword*", 0x0008) ; 0x0008 (ENABLE_WINDOW_INPUT)
    MsgBox(0,'', $aCall[0])

but it doesn't work. :/

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  

×