Jump to content

Windows Error Message


Recommended Posts

needs beta for dllstruct funcs...

Pulled this out of another UDF to make it its own UDF.


;   _GetLastErrorMessage($DisplayMsgBox="")
;   Format the last windows error as a string and return it
;   if $DisplayMsgBox <> "" Then it will display a message box w/ the error
;   Return      Window's error as a string
Func _GetLastErrorMessage($DisplayMsgBox="")
    Local $ret,$s
    Local $p    = DllStructCreate("char[4096]")
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM     = 0x00001000

    If @error Then Return ""

    $ret    = DllCall("Kernel32.dll","int","GetLastError")

    $ret    = DllCall("kernel32.dll","int","FormatMessage",_
    $s  = DllStructGetData($p,1)
    If $DisplayMsgBox <> "" Then MsgBox(0,"_GetLastErrorMessage",$DisplayMsgBox & @CRLF & $s)
    return $s
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
Share on other sites

  • 2 years later...

Good work, although im experiencing some problems, I used it for testing my "InternetConnect" call, the call is 100% tested, but it doesn't matter if i want to connect a real ftp server or a non-existing one, your function always returns "Der Vorgang wurde erfolgreich beendet" (german, something like 'The action has completed successfully').

EDIT: Do you know where the bug is? Is it WinApi GetLastError or is it your function? I'd be grateful for help

Func _FTPConnect($server, $port, $user, $pw)
    $dll = DllOpen("wininet.dll")
    ;Local $h_inet= DllCall('wininet.dll', 'long', 'InternetOpen', 'str', $s_Agent, 'long', $l_AccessType, 'str', $s_ProxyName, 'str', $s_ProxyBypass, 'long', $l_Flags)
    Local $h_inet= DllCall('wininet.dll', 'long', 'InternetOpen', 'str', 'FTP.exe', 'long', 1, 'str', '', 'str', '', 'long', 0)

    ;Local $ai_InternetConnect = DllCall('wininet.dll', 'long', 'InternetConnect', 'long', $l_InternetSession, 'str', $s_ServerName, 'int', $i_ServerPort, 'str', $s_Username, 'str', $s_Password, 'long', $l_Service, 'long', $l_Flags, 'long', $l_Context)
    Local $result = DllCall('wininet.dll', 'long', 'InternetConnect', 'long', $h_inet[0], 'str', $server, 'int', 0, 'str', $user, 'str', $pw, 'long', 1, 'long', 0, 'long', 0)
    If $result[0] = 0 Then
        Return 0
        Return $result[0]
Edited by tannerli
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

  • Recently Browsing   0 members

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