Jump to content

_WinAPI_GetErrorMessage works fully on Win 10 but partially on other Windows


Recommended Posts

Hi,

I'm having a hard time getting the function fully to work on other Windows than Windows:

$ret = _WinAPI_GetErrorMessage('1058')
MsgBox(0,'1', '"' & $ret & '"')
$ret = _WinAPI_GetErrorMessage('-2140993535')
MsgBox(0,'2', '"' & $ret & '"')


Func _WinAPI_GetErrorMessage($iCode, $iLanguage = 0)
    Local $aRet = DllCall('kernel32.dll', 'dword', 'FormatMessageW', 'dword', 0x1000, 'ptr', 0, 'dword', $iCode, _
            'dword', $iLanguage, 'wstr', '', 'dword', 4092, 'ptr', 0)           
    If @error Or Not $aRet[0] Then Return SetError(@error, @extended, '')
    Return StringRegExpReplace($aRet[5], '[' & @LF & ',' & @CR & ']*\Z', '')
EndFunc   ;==>_WinAPI_GetErrorMessage

The first error code (the plus code 1058) will be returned correctly on all Windows.
The second error code (the minus code -2140993535) will be returned correctly only on Windows 10.

Is there a way to make the function work on other Windows versions for minus error codes? Or is there any other way to get the error message using Autoit?

Thanks in advance.

Edited by Factfinder
Link to comment
Share on other sites

34 minutes ago, JohnOne said:

first, swap these lines of code

 _ArrayDisplay($aRet)
    If @error Or Not $aRet[0] Then Return SetError(@error, @extended, '')

I removed the line. However, I had put it there because the function didn't return any extended error.

I edited the script to avoid any confusion. Thank you.

Edited by Factfinder
Link to comment
Share on other sites

Easy now. In each new version of the Windows operating system there are added hundreds or thousands of new error codes and corresponding error messages. The number of error codes and error messages is always increasing.

Why do you expect that all error codes and error messages in Windows 10 also exists in Windows 7? This is a wrong assumption. But the reverse is probably true. All error codes in Windows 7 is also registered in Windows 10.

Link to comment
Share on other sites

11 hours ago, LarsJ said:

Easy now. In each new version of the Windows operating system there are added hundreds or thousands of new error codes and corresponding error messages. The number of error codes and error messages is always increasing.

Why do you expect that all error codes and error messages in Windows 10 also exists in Windows 7? This is a wrong assumption. But the reverse is probably true. All error codes in Windows 7 is also registered in Windows 10.

They've always been there but developers want more and more access to the OS in order to bring a better personal experience to the user.

(or so they say)

They/We want to know what went wrong and why. And so with each new generation of windows, they give the info, usually in dll's, and soon only in that cloud.

Point is, the error codes expand because you and I, demand it.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

20 hours ago, LarsJ said:

Easy now. In each new version of the Windows operating system there are added hundreds or thousands of new error codes and corresponding error messages. The number of error codes and error messages is always increasing.

Why do you expect that all error codes and error messages in Windows 10 also exists in Windows 7? This is a wrong assumption. But the reverse is probably true. All error codes in Windows 7 is also registered in Windows 10.

Not sure how you came to your assumtion, both the error codes are generated by Windows 7. None of them is confined to Window 10. They were there even before Windows 10 existed.

Link to comment
Share on other sites

This two lines work on W7:

$ret = _WinAPI_GetErrorMessage(0x80020009) ; Exception occurred
$ret = _WinAPI_GetErrorMessage(2147614729) ; Same but decimal. Note that it is a positive value. -2147614729 returns nothing

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I had converted my second error code to hex before applying the funtion and it did not work on Windows 7. And on Windows 10 either way works.

In fact we probably don't need to convert the negative code to hex. I have checked it and both Windows versions convert the ngative code to identical positive number.

 

 

 

 

 

Edited by Factfinder
Typo
Link to comment
Share on other sites

I tried

$ret = _WinAPI_GetErrorMessage('-2140993535')

with dec and hex. And it doesn't return an error message on W7. As it returns a message for other codes I assume it is a message code that does not exist on W7.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

-2140993535 (decimal) or 0x80630801 hex) stands for: PEER_E_CERT_STORE_CORRUPTED The certstore is corrupted.
https://msdn.microsoft.com/en-us/library/windows/desktop/hh404142(v=vs.85).aspx
 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...